Wiki Weasel Script



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.

  1. Start with a random string of 28 characters.
  2. Make 100 copies of the string (reproduce).
  3. For each character in each of the 100 copies, with a probability of 5%, replace (mutate) the character with a new random character.
  4. 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).
  5. 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.

Scroll to Top