Evolutionary algorithm: Difference between revisions
→{{header|Raku}}: more FP version and use \r not to scroll
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
(→{{header|Raku}}: more FP version and use \r not to scroll) |
||
Line 6,846:
=={{header|Raku}}==
(formerly Perl 6)
{{works with|rakudo|2015-
<syntaxhighlight lang="raku" line>constant target = "METHINKS IT IS LIKE A WEASEL";
constant mutate_chance = .
constant @alphabet = flat 'A'..'Z',' ';
constant C =
sub mutate { [~] (rand < mutate_chance ?? @alphabet.pick !! $_ for $^string.comb) }
sub fitness { [+] $^string.comb Zeq target.comb }
{ max :by(&fitness), mutate($_) xx C } ... * eq target;</syntaxhighlight>
▲) { printf "%6d: '%s'\n", $++, $parent }</syntaxhighlight>
=={{header|Red}}==
|