More changes
This commit is contained in:
25
scripts/speller.exs
Normal file
25
scripts/speller.exs
Normal file
@@ -0,0 +1,25 @@
|
||||
defmodule Speller do
|
||||
@behaviour Problem
|
||||
alias Types.Chromosome
|
||||
|
||||
def genotype do
|
||||
genes =
|
||||
Stream.repeatedly(fn -> Enum.random(?a..?z) end)
|
||||
|> Enum.take(34)
|
||||
%Chromosome{genes: genes, size: 34}
|
||||
end
|
||||
|
||||
def fitness_function(chromosome) do
|
||||
target = "supercalifragilisticexpialidocious"
|
||||
guess = List.to_string(chromosome.genes)
|
||||
String.jaro_distance(target, guess)
|
||||
end
|
||||
|
||||
def terminate?([best | _]), do: best.fitness == 1
|
||||
|
||||
end
|
||||
|
||||
soln = Genetic.run(Speller)
|
||||
|
||||
IO.write("\n")
|
||||
IO.inspect(soln)
|
Reference in New Issue
Block a user