Commenting on my earlier post on Stockholm door code sequences, a reader writes (well, OK, it’s Geoff):
Can you do the same thing with the rings and the sequences and the words=numbers=objects in a list, and tell me just how long it would take for the proverbial monkey to type up a copy of Hamlet by randomly banging away at a typewriter?
Seriously.
Geoff, you’re right, that monkey is indeed proverbial. Wikipedia has a very interesting article about him and the various guises in which he and his infinite siblings have been bashing away at typewriters for nearly 100 years now, ever since he was evoked by French mathematician Émile Borel to illustrate an otherwise not-too accessible law of mathematics.
I think the reason our typing monkey has entered popular consciousness to the extent he has is that he straddles two of our fascinations: Our obsessive habit as a species to seek out patterns in nature; and infinity, around which we just never manage to wrap our minds, try as we might.
The reason for the first of these two fascinations, I think, is that we humans are really just finely honed cause-and-effect detectors, hoping to use this skill to avoid harm long enough to procreate. When our detectors misfire — when we generate false positives — we notice coincidences. How we deal with coincidences depends on our ability to intuit the odds of unlikely juxtapositions occurring randomly (and they do occur). Most of us are terrible at such estimations, so we end up turning coincidences into meaningful events, letting them fuel our superstitious beliefs.
We’re suddenly in the middle of a digression here, I know, but there is an interesting corollary example of this: People who buy lottery tickets of the PowerBall variety avoid choosing a sequence like 1,2,3,4,5 and 6; it just doesn’t look random enough to win. In fact, if that were the only option available, I suspect many habitual players would not be willing to pay for it, even though the chance of that sequence winning is exactly the same as their preferred “random” sequence, of which “type” there are far more.
Because the number of sequences in which the average lottery player can detect a pattern is far lower than the total number of possible sequences, as a group “sequences in which I see a pattern” wins less often than “sequences in which I can’t see a pattern.” This much is true. The mistake comes in thinking that membership of the larger group increases a specific sequence’s chances of being selected at random.
An exploration of this fallacy propels Inflexible Logic by Russell Maloney, a wonderful short story from The New Yorker circa 1940. In it, the protagonist decides to test empirically whether six chimpanzees eventually do end up writing all the works in the British Museum — with remarkable results.
And one of my favorite writers, Jorge Luis Borges, wrote The Library of BabelBoth these short stories are worth copying and pasting into a word processing document, printing out and reading, if you have a spare half hour., a short story which explores the futility of deriving meaning from patterns found in sequences if all possible sequences exist. Who else but Borges would think to use that as a plot device!?
This brings us back to the problem at hand. Although our typing monkey has had much coverage on the web, I have not found an actual calculation of the probability he would type out a copy of Hamlet in any given sitting. So, Geoff, I will oblige you:
The calculation is very simple. Take this copy of Hamlet. It contains 32,197 words made from 194,270 characters. The “alphabet” of possible characters includes both lowercase and uppercase letters, punctuation marks and spaces — let’s say 64 characters in total. The chance that a monkey randomly types out Hamlet in a given sitting, then, is one in 64194,270. According to Mathematica, that equals one in 3.833 x 10350,886 — a staggeringly small chance.
Another way to conduct this experiment would be to find and then line up 194,270 monkeys and put a typewriter in front of each of them. We let all of them hit a single key each at a time, and string together the result. If we manage to train them to type one character per second, we get a potential Hamlet text every second. There have been 441,504,000,000,000,000, or 4.415 x 1017 seconds since the Big Bang, approximately, so if our monkeys had started typing soon after the birth of the universe, the probability that they’d have something for us by now is 1-(1-1/(3.833 x 10350,886))4.415 x 1017Unfortunately, even Mathematica gets an overflow error trying to calculate that. Methodology: First you calculate the probability of a copy of Hamlet not being typed at a given sitting (1-1/(3.833 x 10350,886)), then you raise that to the power of the number of sittings, in our case the number of seconds since the Big Bang, 4.415 x 1017. This gives us the probability of Hamlet not having been written after all these seconds; to find the probability that it has, just subtract that number from 1..
That’s a vanishingly small chance. According to our French mathematician Borel, who actually thought a great deal about this, the class of events with probabilities of less than one in 1050 of occurring are negligible on a cosmic scale. The probability our monkeys will type Hamlet is certainly in that class. However, Borel also came up with a class of events with probabilities that are negligible on a “supercosmic” scale — probabilities of less than one in 101010, or 1010,000,000,000— something exceedingly unlikely to happen even if given an inordinate number of universes to play with. We’d definitely have a text of Hamlet before long on this scale, according to our calculations.
But Borel gave an example of an event with a negligible chance of occurring even at the supercosmic scale: the chance that a container holding a mixture of a fair number of oxygen atoms and nitrogen atoms would spontaneously have all the oxygen atoms jump to one side and the nitrogen atoms to the other side, thus organizing itself, decreasing the system’s entropy and breaking the Second Law of Thermodynamics.
We can therefore state with confidence that monkeys will type Hamlet long before the Second Law of Thermodynamics breaks.
If you haven’t yet read ‘The Crying of Lot 49’, you should.
Richard Dawkins used the haphazard primate playwrights to illustrate to power of natural selection. I don’t remember in which book or exactly how the experiment was set up, but you had a perfect copy of ‘Hamlet’ after only 25 generations or so.
I wouldn’t be at all surprised to find out that, contra your implication above, 1,2,3,4,5,6 is in fact the single most popular set of lottery numbers. Fact is, for all that we think we’re picking numbers “at random”, it’s almost impossible not to pick numbers with some sort of order to them — which is why smart lottery players (were such people to exist) always choose the “quick pick” option. In general, if the numbers turn out to be vaguely ordered, the jackpot is split between a much larger number of players.
Shakespeares apor och talande smörsångare
Ge tilräckligt många apor tillräcklig många skrivmaskiner, och förr elle senare kommer någon att hamra fram Hamlet. Stefan Geens…
This article from today gives a whole new perspective on the question, I think:
“Klaas told silicon.com: “Whatever people say about infinite outcomes and infinite possibilities this research makes me think monkeys would never write the entire works of Shakespeare using a Mac.””
http://hardware.silicon.com/desktops/0,39024645,39129163,00.htm