Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
12
Task/Evolutionary-algorithm/Raku/evolutionary-algorithm.raku
Normal file
12
Task/Evolutionary-algorithm/Raku/evolutionary-algorithm.raku
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
constant target = "METHINKS IT IS LIKE A WEASEL";
|
||||
constant @alphabet = flat 'A'..'Z',' ';
|
||||
constant C = 10;
|
||||
|
||||
sub mutate(Str $string, Real $mutate-chance where 0 ≤ * < 1) {
|
||||
$string.subst: /<?{ rand < $mutate-chance }> . /, @alphabet.pick, :global
|
||||
}
|
||||
sub fitness(Str $string) { [+] $string.comb Zeq target.comb }
|
||||
|
||||
printf "\r%6d: '%s'", $++, $_ for
|
||||
@alphabet.roll(target.chars).join,
|
||||
{ max :by(&fitness), mutate($_, .001) xx C } ... target;
|
||||
Loading…
Add table
Add a link
Reference in a new issue