What to do with an infinite number of monkeys at 3:43 in the morning

Control F1 Product Development Director Dale Reed shares what keeps him up at night…

As an insomniac, my main problem is that my brain sometimes just doesn’t want to go to sleep. Like a petulant child it will sit there either singing the same song over and over again just to annoy me (and never a good one either), or spend hours obsessing over completely ridiculous things. My brain, who throughout the day is normally reasonably helpful, at night suddenly becomes my nemesis, Moriarty to my Holmes, Hyde to my Jekyll, Moby Dick to my Captain Ahab (you get the point). Going forward this anti- brain alter-ego will be referred to as Geoffrey. We all have a Geoffrey in our lives, that annoying friend that thinks he knows everything about every subject ever and just won’t shut up…

Recently, I had read an article about a chap who had decided to test out the infinite monkey theorem (you know the one, if you gave a monkey a typewriter and an infinite amount of time, it would eventually be able to write the complete works of Shakespeare).

Though I always applaud time spent on completely pointless tasks, I took umbrage at his methods. To test out the theorem, he was using distributed computing to generate random words. If any computer created a word that actually made sense and was used in the complete works of Shakespeare, then it was slotted into place throughout the works (so, for example, if it randomly came up with the word ‘of’, then all of the ‘of’s within Shakespeare’s complete tomes were considered complete).

To me this is the application of the Eric Morecambe methodology, i.e. all the right words, just not necessarily in the right order! If I’m employing a monkey and presumably coughing up for all the bananas, then I want to receive the complete works of Shakespeare, written one word after the other as the bard himself would well expect! Just generating random words then plonking them in place when they happen to fit really doesn’t seem in keeping with the theorem IMHO.

To me that was the end of it, nice idea, not too keen on the implementation, move along.

Unfortunately Geoffrey had different ideas.

So there I am, 3:43 in the morning, can’t sleep. Then Geoffrey pipes up…

“What are the odds of a monkey being able to type the complete works of Shakespeare in one go anyway?”

And then spent the next three hours working it out. I don’t know what he’s on but I’d really like him to stop taking it.

So, here it is, my calculations (Ok, Ok my ridiculous semi-conscious brain’s calculations) for getting the complete works of Shakespeare, start to finish.

First, we need to calculate the odds of actually being able to type the complete works of Shakespeare, monkeys or no.

This is actually pretty straight forward:

  1. Find out how many different individual characters Shakespeare used in his text.
  2. Find out how many characters there are in his complete works.
  3. Do some long, long, long, long, long multiplication!

Item 1, number of characters. Now bearing in mind I was trying to sleep and completely refused to get out the iPad and start Googling, despite Geoffrey’s insistence, I just guessed. I reckoned obviously you need a-z (I decided not to worry about upper and lower case), 0-9, spaces, full stops, commas, apostrophes etc. So 26 alpha characters, 10 numeric, plus I reckoned about 14 ‘other’ would be enough, 50 characters in total. It’s a nice round number and should cover most things I hoped.


In actuality, once I checked properly there are 55 characters used in the version I have, as follows:

!”&'(),-.:;<?[] _0123456789abcdefghijklmnopqrstuvwxyz|}

So the guesswork wasn’t a million miles away!

We also need to consider the carriage return, so it’s actually 56 in total.

The really sad fact about the above is that I had to write some code to scrape the complete works to pull out this list of characters. I think Geoffrey is getting surreptitiously involved in my waking life now too!)

So now to consider the odds. First I’ve decided to give our Monkey a PC instead of a typewriter. I mean, this isn’t the middle ages, plus it means we don’t have to worry about replacing paper etc., or our simian friend taking the paper and eating it or using it to wipe… Well, let’s not think about it! I also realised we’d need a special keyboard making, with just our 50 characters on it. It’d be a nightmare if he got to the last page then hit the escape key or something by mistake! So, we have our monkey. We have our special 50 character keyboard. His finger is poised and ready to hit the first key. What are the odds that our Simian employee hits the correct first character in our work? 1 in 50, right? There’s a 1 in 50 chance that the key he presses is the correct first character. Now, let’s put that aside for a second and consider the second character. What are the odds that he presses the second character correctly? 1 in 50 again? Well, yes, BUT, unfortunately, if it were that easy we’d all win the lottery every week.

The problem is we need to calculate the odds of him hitting the first key correctly AND then the second key, not each key individually. So this means, the chances are 1 in 50^2. Or 1 in 2500 in other words. Third key we have to multiply by 50 again (1 in 50^3) and so on. As an example, in my copy of the complete works the first sentence is from the first sonnet, and is ‘from fairest creatures we desire increase,’, which is 42 characters long. To get that entire string, we’re looking at odds of 1 / 50^42. Or in other words, one in 26,539,768,742,087,885,687,527,987,706,116,853,281,844,223,293,134,704,738,830,807,228,099,854,336.

For one pretty short sentence. Hmm. Even the lottery is looking easy to win against those kinds of odds!

The complete works of Shakespeare is approximately 5 million characters long.

So the odds of writing out the complete works of Shakespeare using a 50 character keyboard is 1 in 50^5,000,000. Don’t worry, I’m not going to write that out in long hand; however we can determine that it’s a number with around 10 million digits. In other words, twice as many digits as the complete works of Shakespeare. Basically, it’s a lot. More than Microsoft had in mind when they created BigInt, anyway!

Of course, all of this is based on a single monkey with nothing better to do. Now to me if we’re going to apply infinity to the equation (i.e. infinite time), why not just apply that to the number of monkeys instead?

So, what if we had an infinite number of monkeys, with a keyboard each?

Well, in that case, the odds are pretty irrelevant. As ridiculously huge as our odds are, our number of monkeys is infinitely huger, and any number divided by infinity is basically zero (just as any number divided by zero is effectively infinity). So, we can then determine that at least one of our infinite number of monkeys will, on the first go, immediately type out the complete works of Shakespeare, from start to finish, no mistakes. Indeed, as we have an infinite number of monkeys, then actually multiple monkeys will do so. Taking this to a logical conclusion, a subset of our infinite monkeys will write the complete works of Shakespeare the first time they attempt it, and as any subset of infinity is itself (arguably!) also infinity, we can surmise that an infinite number of monkeys will write the complete works of Shakespeare, first time.

Putting aside the mother of all copyright battles that is bound to ensue (and if anyone is going to start the mud-slinging, it’s likely to be an infinite number of monkeys!), what does that give us?

Well, to me the original theorem just isn’t thinking very logically. If you are going to apply infinity to the argument, clearly giving us an infinite number of monkeys to work with is way more sensible than a single monkey having an infinite amount of time. Taking into account time required for banana breaks, throwing feces at passers by etc., we can I think safely assume one key press every 2 seconds on average. 5 million key presses = 10 million seconds. Which is 166,667 minutes, which is 2,778 hours, which is just under 116 days.

So in conclusion, with an infinite number of monkeys, we will receive an infinite number of copies of the complete works of Shakespeare, within around 116 days.

And, hopefully, get some sleep.

…Of course, the fact that I decided not to include upper case characters has been bothering me…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s