### A Universe of Monkeys Couldn't Type Hamlet

Really. There's an idea going around that a monkey typing for an infinite time would eventually type the complete works of Shakespeare. In fact the age of the Universe (about 14.7 billion years) is tiny compared to the time it would take for that tireless monkey to peck out Hamlet, never mind all the other great works of the Bard.

A monkey (or machine) picking random letters has one chance in 26 of correctly choosing the first letter of Hamlet, which happens to be an "A" (Actus Primus. Scoena Prima.) There's one chance in 676 (26 X 26) of choosing the first two letters. The probability goes down exponentially, so to get the first 20 letters correct there's already only one chance in 26

The text of Hamlet, even without punctuation and spaces, contains 133,874 letters which means the probability of a randomly picking them all in the right order is one in 3.4×10

Even if the universe were filled with monkeys and they'd been typing since the Big Bang the chance that they would have produced Hamlet would still be less than one chance in 10

But in the 1980s Richard Hardison of Glendale College wrote a computer program that generated phrases randomly while preserving the positions of individual letters that happened to be correctly placed (in effect, selecting for phrases more like Hamlet's). Kinda like how evolution selects for adaptive changes produced by mutations. On average, the program re-created the phrase TOBEORNOTTOBE in just 336 iterations, less than 90 seconds. Even more amazing, it could reconstruct Shakespeare's entire play in just four and a half days. Now that's the power of natural selection.

As Shakepseare wrote: Though this be madness, yet there is method in 't.

A monkey (or machine) picking random letters has one chance in 26 of correctly choosing the first letter of Hamlet, which happens to be an "A" (Actus Primus. Scoena Prima.) There's one chance in 676 (26 X 26) of choosing the first two letters. The probability goes down exponentially, so to get the first 20 letters correct there's already only one chance in 26

^{20}or one in 19,928,148,895,209,409,152,340,197,376. That's about the same as buying four tickets in consecutive lotteries and winning the jackpot each time.The text of Hamlet, even without punctuation and spaces, contains 133,874 letters which means the probability of a randomly picking them all in the right order is one in 3.4×10

^{183946}. That's a very big number. Consider that there are only about 10^{79}atoms in the observable universe and only 10^{17}seconds have elapsed since the Big Bang.Even if the universe were filled with monkeys and they'd been typing since the Big Bang the chance that they would have produced Hamlet would still be less than one chance in 10

^{183800}.But in the 1980s Richard Hardison of Glendale College wrote a computer program that generated phrases randomly while preserving the positions of individual letters that happened to be correctly placed (in effect, selecting for phrases more like Hamlet's). Kinda like how evolution selects for adaptive changes produced by mutations. On average, the program re-created the phrase TOBEORNOTTOBE in just 336 iterations, less than 90 seconds. Even more amazing, it could reconstruct Shakespeare's entire play in just four and a half days. Now that's the power of natural selection.

As Shakepseare wrote: Though this be madness, yet there is method in 't.

## Comments