Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Evolutionary-algorithm/11l/evolutionary-algorithm.11l
Normal file
19
Task/Evolutionary-algorithm/11l/evolutionary-algorithm.11l
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
V target = Array(‘METHINKS IT IS LIKE A WEASEL’)
|
||||
V alphabet = ‘ ABCDEFGHIJLKLMNOPQRSTUVWXYZ’
|
||||
V p = 0.05
|
||||
V c = 100
|
||||
|
||||
F neg_fitness(trial)
|
||||
R sum(zip(trial, :target).map((t, h) -> Int(t != h)))
|
||||
|
||||
F mutate(parent)
|
||||
R parent.map(ch -> (I random:() < :p {random:choice(:alphabet)} E ch))
|
||||
|
||||
V parent = (0 .< target.len).map(_ -> random:choice(:alphabet))
|
||||
V i = 0
|
||||
print((‘#3’.format(i))‘ ’parent.join(‘’))
|
||||
L parent != target
|
||||
V copies = ((0 .< c).map(_ -> mutate(:parent)))
|
||||
parent = min(copies, key' x -> neg_fitness(x))
|
||||
print((‘#3’.format(i))‘ ’parent.join(‘’))
|
||||
i++
|
||||
Loading…
Add table
Add a link
Reference in a new issue