More changes

This commit is contained in:
2022-06-28 08:57:51 +02:00
parent 0b318ac0e4
commit e367229253
6 changed files with 129 additions and 20 deletions

25
scripts/speller.exs Normal file
View 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)