Introduction
This page contains a JavaScript with an algorithm of Dawkins’ weasel as suggested on the Wikipedia page: Weasel program.
According to that page, a “Weasel” style algorithm could run as follows.
- Start with a random string of 28 characters.
- Make 100 copies of the string (reproduce).
- For each character in each of the 100 copies, with a probability of 5%, replace (mutate) the character with a new random character.
- Compare each new string with the target string “METHINKS IT IS LIKE A WEASEL”, and give each a score (the number of letters in the string that are correct and in the correct position).
- If any of the new strings has a perfect score (28), halt. Otherwise, take the highest scoring string, and go to step 2.
Click the ‘Run Weasel’ button to repeat the simulation. Do this a few times to see what happens.
Then go to ‘My Weasel Script‘, which is a slightly modified version but with a better method of selecting the best intermediate sentence.
Tip: Hide this introduction text while running the simulations.
Simulation result
Now have a look at ‘My Weasel Script‘. It is a similar script, but with a different (better) method of selecting an improved sentence.