...

/

Using the New Framework in spelling word problem

Using the New Framework in spelling word problem

Get to know how the new framework works in spelling word problem.

We'll cover the following...

To illustrate the power of our new framework, we’ll use it to solve a new basic problem: spelling. We’ll teach your algorithm to spell an impossibly long word: “supercalifragilistic”.

Start by creating a new file called speller.exs in scripts and define a new problem:

Press + to interact
defmodule Speller do
@behaviour Problem
alias Types.Chromosome
def genotype do: # ...
def fitness_function(chromosome) do: # ...
def terminate?(population), do: # ...
end

Now define a Problem implementation for the tasks. In this chapter, we learned there are three parts to every problem: a genotype, a fitness function, and termination criteria.

The first thing to decide is the genotype. The goal is to spell “supercalifragilistic”, which is a 20-letter word. That means the search space is all 20-letter words. We can define the genotype like this:

Press + to interact
def genotype do
genes =
Stream.repeatedly(fn -> Enum.random(?a..?z) end)
|> Enum.take(20)
%Chromosome{genes: genes, size: 20}
end

The ...