In computer science, a genetic algorithm is an optimisation/search/sort algorithm that uses genetic and evolutionary selection principles to solve computational problems.

The weasel program, aka Dawkin’s weasel, is a thought experiment that demonstrates evolutionary principles using a computer program to “evolve” a random string of characters into a target piece of text, over a series of generations, optimised by selecting the offspring of each generation that closest matches the desired outcome.

Why is this useful?

Well, it’s not really, but it generates a basic principle that is very useful.

Provided that you have a mechanism of detecting the desired outcome, and which of the generated children is closer to it, you can use this tool to solve remarkably complicated problems, and to do so surprisingly quickly. It doesn’t scale well to massively complicated domains (e.g. designing aeroplanes), but can be used quite successfully in smaller, more focussed domains (optimising video compression, sorting strings, modifying seed values in procedurally generated terrain, etc).

Anyway, it kept me entertained while I finished my beer.

The code

Leave a Reply