Evolutionary algorithm: Difference between revisions
Content deleted Content added
m →{{header|Sidef}}: modified the code to work with Sidef 2.30 |
|||
Line 5,596:
=={{header|Sidef}}==
{{trans|Perl 6}}
<lang ruby>define target = "METHINKS IT IS LIKE A WEASEL"
define mutate_chance = 0.08
define alphabet = [
define C = 100
func fitness(str) { str.chars ~Z== target.chars -> count(true) }
func mutate(str) { str.gsub(/(.)/, {|s1| 1.rand < mutate_chance ? alphabet.pick : s1 }) }
for (
|