40 lines
1.2 KiB
Plaintext
40 lines
1.2 KiB
Plaintext
PUT "ABCDEFGHIJKLMNOPQRSTUVWXYZ " IN alphabet
|
|
|
|
HOW TO RETURN initial.state target:
|
|
SHARE alphabet
|
|
PUT "" IN state
|
|
FOR c IN target: PUT state^choice alphabet IN state
|
|
RETURN state
|
|
|
|
HOW TO RETURN state fitness target:
|
|
PUT #target IN score
|
|
FOR i IN {1..#target}:
|
|
IF state item i = target item i: PUT score-1 IN score
|
|
RETURN score
|
|
|
|
HOW TO RETURN chance mutate state:
|
|
SHARE alphabet
|
|
PUT "" IN mutated
|
|
FOR i IN {1..#state}:
|
|
SELECT:
|
|
random < chance: PUT choice alphabet IN next
|
|
ELSE: PUT state item i IN next
|
|
PUT mutated^next IN mutated
|
|
RETURN mutated
|
|
|
|
HOW TO EVOLVE TOWARD target:
|
|
PUT 0.1 IN mutation.rate
|
|
PUT 100 IN generation.size
|
|
PUT initial.state target IN state
|
|
WHILE state fitness target > 0:
|
|
WRITE (state fitness target)>>2, ": ", state/
|
|
PUT {} IN next.generation
|
|
FOR i IN {1..generation.size}:
|
|
PUT mutation.rate mutate state IN child
|
|
PUT child fitness target IN score
|
|
PUT child IN next.generation[score]
|
|
PUT next.generation[min keys next.generation] IN state
|
|
WRITE (state fitness target)>>2, ": ", state/
|
|
|
|
EVOLVE TOWARD "METHINKS IT IS LIKE A WEASEL"
|