#35 Mutating Strings into Weasels (methinks.rb)

This script is based on a program from Richard Dawkins’ The Blind Watchmaker (W.W. Norton, 1996).The program demonstrates a simplified model of asexual natural selection, starting with a String consisting of random characters and successively mutating it to produce “children” that differ from the parent. The program then selects the “best” child String (meaning the one that most closely matches the target String methinksitislikeaweasel, a reference from Hamlet) to be the next generation’s parent. This process continues until the parent String matches the target String.

Let’s implement Dawkins’ process in Ruby.

Note

Dawkins wrote his program to demonstrate a version of cumulative selection over time ...

Get Ruby by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.