Monday, December 20, 2010

Shakespeare's Monkey

Most people have heard of the theory that a monkey given an infinite amount of time and a computer will eventually type out the complete works of Shakespeare.

I of course wanted to test the theory, I do random things like that sometimes.

Rather than digitise the complete works of Shakespeare I thought I would start with the famous phrase:

"To be or not to be"
So programmed in perl with a mysql database attached a random number generator tries to recreate the famous phrase. With a bit of calculation it works out the percentage match and records the monkey world record.

Try it for yourself here - Monkey Shakespeare.

2 comments:

eifionglyn said...
This comment has been removed by the author.
eifionglyn said...

I am not a statistician so all this may be completely wrong: However, there are 18 characters in "to be or not to be" (including spaces) Each character is a choice of one out of 27 possible characters (26 letters + space). Assuming each character equally likely and independent, the possible number of permutations that the monkey could type is given by 27 raised to the power of 18, which is erm... just a minute... carry the two.... 5.81 *10^25.

That's a lot.

Say the monkey can type 2 characters a second, it would take it 13.5 seconds per attempt. Let's assume the monkey can type a little quicker and call it 10 seconds per attempt to make the math easy.

Assuming the monkey doesn't take a break to eat, sleep or check facebook, the monkey would have to work for 1.8 * 10^19 years before we'd expect to have the phrase appear once, by random chance.

This is 1.3 Billion times the current age of the universe.

I hope you have a plentiful supply of bananas.