A MILLION MONKEYS, A MILLION YEARS
Home
                                     
 
At one time or another, we’ve all probably heard the claim that a million monkeys typing for a million years would write all of the works of Shakespeare or write all of the books in the British Museum – or something similar.   Is this true?

First let's think about the context in which the statement is made.   It's usually an implicit, sometimes explicit, suggestion that if you randomly pound away on a keyboard long enough, you'll write something – purely by accident – that makes sense.   How could this happen?   Instead of saying all the works of Shakespeare I could just as easily say all the dialog from every Hitchcock movie.   Or I could say all the elements of the IRS tax code.   I could also say the written descriptions for the Saturn 5 Rocket.   Another possibility is all of the State of the Union addresses given by every past U.S. President.   And why couldn't we include, in the last category, the State of the Union addresses given by a number of future U.S. Presidents?   After all, there is no way the monkeys could know (or care) whether the stuff they write is from the past or the future.

And why would what they write be restricted to the actual works of Shakespeare, or the actual blueprints for the Saturn 5?   If, in a million years, they could write those things, they could (and would) write Shakespeare's plays with different endings, or Saturn 5 descriptions with one or more errors.   And they would also write Shakespeare's plays with Hitchcock movie dialog interspersed, or State of the Union addresses combined with elements of the U.S. tax code.   They would write Shakespeare's plays with Acts three and one swapped, and Shakespeare's plays with all the dialog backwards – instead of to be or not to be that is the question, the dialog would be question the is that be to not or be to.   And they would also write a version with niotseuq eht si taht eb ot ton ro eb ot.   There would be a version with to be or not to be niotseuq eht si taht.

They would write a version where every sentence is duplicated exactly twice, and another where every sentence is duplicated exactly three times, and another where every word is duplicated exactly twice – to to be be or or not not to to be be that that is is the the question question.   There would be a version with every word followed by its twin written backward to ot be eb or ro not ton to ot be eb that taht is si the eht question noitseuq.   And there would be a version where every word is delineated by the letters xx, as in xxtoxx xxbexx xxorxx xxnotxx xxtoxx xxbexx xxthatxx xxisxx xxthexx xxquestionxx.   The possibilities are (literally!) endless.

After all this, a few things should be clear.   Suppose we pick out a 100-word paragraph from Sheakespeare's plays.   Or we could pick 100 words from a Tom Clancy novel.   Or 100 words from the Gettysburg address.   It doesn't matter which 100 words we pick.   If, in a million years, the million monkeys would type 100 words from one of Shakespeare's plays, or one of Tom Clancy's novels, or the Gettysburg address, they would have to type every possible set of 100 words.   So this gives us a way of calculating some answers.

Let's do a simpler problem first.   Start by assuming the monkeys use typewriters with only 28 keys – 26 letters of the alphabet, a space, and a period.   Ignore upper and lower cases; ignore numbers; ignore punctuation; ignore parentheses, dashes, commas, semicolons.   And rather than try to determine if they can type all of Shakespeare, let’s just determine whether they will type a recognizable sentence:   to be or not to be, that is the question.   This sentence has forty characters, including spaces and the period.

Now we don't have to use this sentence – any forty-character sentence will do.   In fact, any forty characters will do.   The only way we can be certain the monkeys will type a particular forty characters is if they type every possible set of forty characters.   So let's see how long it would take for them to do this.
 
  Top
 
HOW LONG TO WRITE THE ONE SENTENCE?
 
The sentence we're considering is to be or not to be, that is the question.   It has forty characters, including spaces and the period (we're going to ignore the comma and upper cases).   We're actually going to calculate how many monkeys it will take to type out all possible forty-character sentences.   Because we know that if they do that, they will certainly type this one.

Start with one character.   There are obviously 28 possible phrases which use only one character:     a,   b,   c,   d,   e,   f,   g   ,   .   .     .   ,   x,   y,   z,   .,   and   _.

Here I have denoted a space by an underscore, so the last two "phrases" are a period and a space.   There are 28 x 28 = 784 possible two-character phrases:

aa,   ab,   ac,   ad,   ae,   .     .     .     ,   ax,   ay,   az,   a.,   and   a_ are the first 28 (the last two are   "a"   followed by a period and   "a"   followed by a space).   The next 28 are:

ba,   bb,   bc,   bd,   be,   .     .     .   bx,   by,   bz,   b.,   b_

(the last two of these are   "b"   followed by a period and   "b"   followed by a space).   The next 28 are:

ca,   cb,   cc,   cd,     .   .   .   cx,   cy,   cz,   c.,   c_,   and so on.

The last 84 of the 784 two-character phrases are:

za,   zb,   zc,   zd,     .   .   .   zz,   z.,   z_; followed by .a,   .b,   .c,   .d,   .e,   and so on up to .x,   .y,   .z,   ..,   ._;   finally followed by   _a,   _b,   _c,   _d,   _e,   and so on up to _x,   _y,   _z,   _.,   and __.   The last two are, respectively, a space followed by a period and two consecutive spaces.

The number of possible three-character phrases will be 28 x 28 x 28 = 21952.

The minimum number of characters the monkeys must type to get all possible one-character phrases is 28.   The minimum number of characters the monkeys must type to get all possible two-character phrases is 2 x 28 x 28   =   1568.

I have said "minimum number of characters" because there is the possibility some of the phrases the monkeys type will be duplicates – a monkey might type xrwe jxco itr and later type the same thing; or another monkey might type it as well.   I'm making the problem easier by ignoring this possibility.   I'm also assuming that each monkey is as likely to type an "a" or a "z" as a "p" or a "."

The minimum number of characters the monkeys must type to get all possible three-character phrases is 3 x 28 x 28   (there are 28 x 28 x 28 possible three-character phrases, multiplied by three characters).   Note that the set of all one-character phrases is a subset of all two-character phrases; the set of all two-character phrases is a subset of all three-character phrases, and so on.

So the minimum number of characters the monkeys must type to get all possible N-character phrases is N x 28 x 28 x 28 ... x 28, where there are N of the factors 28.   (This can be written as N x 28N).   For the case we're examining, 40 characters, the minimum number of characters the monkeys must type is 40 x 2840.   This is the minimum number of characters the monkeys must type to get all possible forty-character phrases.

Thanks to the magic of an Open Office spreadsheet, we find that
 
  2840   =   7.69 x 1057
and
40 x 2840   =   3.08 x 1059
  These are very big numbers!!
  Top  
 
HOW MANY MONKEYS?
 
So how many monkeys do we need?   First, let’s not use just a million monkeys.   Let’s use a hundred billion (1011) – this is over ten times the number of people on Earth.   Further, let's assume that they’ve been typing away for ten billion (1010) years – even though the earth has been around for only about 4.5 billion years.   Let’s also assume that every star in the Milky Way galaxy (there are about 200 billion, or 2 x 1011, stars) has a planet with this many monkeys, who have been typing for ten billion years.  How many monkeys is this?

 
  1011  monkeys/star   x   2 x 1011 stars   =   2 x 1022  monkeys  
 
Let's further assume that each monkey has been typing 120 words per minute for ten billion years.   There are five characters in a word, so 120 words per minute is 600 characters per minute, or ten characters per second.   Now the number of seconds in a year is 60 seconds/minute x 60 minutes/hour x 24 hours/day x 365 days/year.   Using our spreadsheet, this is   3.15 x 107  seconds .   We multiply this by ten characters per second and by ten billion years:

 
  10 character/sec   x   3.15 x 107 sec/year   x   1010 years =
3.15 x 1018 characters
 
 
This is the number of characters each monkey types in ten billion years; multiply by the number of monkeys:
 
  3.15 x 1018 characters/monkey   x   2 x 1022 monkeys   =
6.3 x 1040 characters
 
 
This is the number of characters typed by all the monkeys in ten billion years of typing.   So, have the monkeys typed all possible sentences in this time?   If they have, they would have written all the works of Shakespeare (and anyone else).   Now we know the minimum number of characters the monkeys have to type to produce all possible three-character phrases – it's 3 x 283   which is 65,856.   To type all possible five-character phrases requires a minimum of 5 x 285   characters; this is about 87 million.   To type all possible ten-character words, the monkeys would have to type a minimum of 3 x 1015 characters.   For the minimum number of characters required for different phrase lengths, see the table below.
 
  Top  
 
  MINIMUM NUMBER OF CHARACTERS MONKEYS MUST TYPE TO CREATE ALL PHRASES OF SPECIFIED LENGTH  
LENGTH OF PHRASE IN CHARACTERS

N
NUMBER OF POSSIBLE PHRASES

28N
MINIMUM NUMBER OF CHARACTERS

N x 28N
LENGTH OF PHRASE IN CHARACTERS

N
NUMBER OF POSSIBLE PHRASES

28N
MINIMUM NUMBER OF CHARACTERS

N x 28N
1
28
28
26
4.23 x 1037
1.1 x 1039
2
784
1568
27
1.18 x 1039
3.2 x 1040
3
21,952
65,856
28
3.31 x 1040
9.28 x 1041
4
614,656
2,458,624
29
9.28 x 1041
2.69 x 1043
5
1.72 x 107
8.6 x 107
30
2.60 x 1043
7.80 x 1044
6
4.81 x 108
2.89 x 109
31
7.28 x 1044
2.26 x 1046
7
1.35 x 1011
9.45 x 1011
32
2.04 x 1046
6.52 x 1047
8
3.78 x 1011
3.02 x 1012
33
5.70 x 1047
1.88 x 1049
9
1.06 x 1013
9.52 x 1013
34
1.60 x 1049
5.43 x 1050
10
2.96 x 1014
2.96 x 1015
35
4.47 x 1050
1.56 x 1052
11
8.23 x 1015
9.12 x 1016
40
7.70 x 1057
3.08 x 1059
12
2.32 x 1017
2.79 x 1018
45
1.32 x 1065
5.96 x 1066
13
6.50 x 1018
8.45 x 1019
50
2.28 x 1072
1.14 x 1074
14
1.82 x 1020
1.55 x 1021
55
3.92 x 1079
2.15 x 1081
15
5.10 x 1021
7.64 x 1022
60
6.76 x 1086
4.05 x 1088
16
1.43 x 1023
2.28 x 1024
65
1.16 x 1094
7.55 x 1095
17
4.00 x 1024
6.79 X 1025
70
2.00 x 10101
1.40 x 10103
18
1.12 x 1026
2.01 x 1027
75
3.44 x 10108
2.58 x 10110
19
3.13 x 1027
5.95 x 1028
80
5.92 x 10115
4.74 x 10117
20
8.77 x 1028
1.75 x 1030
85
1.02 x 10123
8.67 x 10124
21
2.46 x 1030
5.16 x 1031
90
1.75 x 10130
1.58 x 10132
22
6.88 x 1031
1.51 x 1033
95
3.02 x 10137
2.87 x 10139
23
1.93 x 1033
4.43 x 1034
100
5.20 x 10144
5.20 x 10146
24
5.39 x 1034
1.29 x 1036
105
8.95 x 10151
9.39 x 10153
25
1.51 x 1036
3.77 x 1037
110
1.54 x 10159
1.69 x 10161
Top  
 
THE ANSWER
 
To type all possible 40-character phrases would require that the monkeys type a minimum of 3.1 x 1059 characters; as we saw above.   But we also saw that all these monkeys, in ten billion years, would type only 6.3 x 1040   characters.

So despite having all these monkeys, and all this time, the monkeys could not type all possible 40-character phrases.   And I ignored the possibility of duplicate phrases.   From the table, we see that the monkeys would only type all possible 27-character phrases.   If we were to consider filling every known galaxy in the universe with monkeys, that would only increase the number of characters they type by a factor of 1012.   This would make it possible for the monkeys to type all possible 35-character phrases – not nearly enough.

As far as typing all of the works of Shakespeare or typing all of the books in the British Museum – it's clear from the Table that the numbers of monkeys and the number of years – as astronomical as they are – are woefully inadequate.   As the number of characters in the phrase grows, the minimum number of characters the monkeys must type grows geometrically.   That minimum number, to get all possible N-character phrases, is   N x 28N.   So that by the time we reach 100-character phrases, the minimum number of characters the monkeys must type exceeds   10146.

Now a single page can easily contain many hundreds of characters.   So there is no way any set of monkeys in the observable universe could ever type all possible letters on a single page, let alone all the works of Shakespeare.

 
 
Covering a planet with monkeys, in every solar system in the galaxy, and every galaxy in the known universe, and allowing them to type away for ten billion years – it couldn't be guaranteed that they would even type the sentence:

TO BE OR NOT TO BE THAT IS THE QUESTION.


 
  Top