The infinite monkey theorem states that if a group of monkeys were to hit keys at random on typewriters for an infinite amount of time, they could eventually write any book imaginable. The original idea was proposed by Émile Borel in 1913, and it hasn’t lost its relevance. So we’ve decided to take a stroll across an infinite planet populated by infinite monkeys pounding on infinite typewriters. Are you in?
The original idea of the infinite monkey theorem was put forward by Émile Borel in his book Mécanique Statistique et Irréversibilité, published in 1913. Initially, Borel argued that if a million monkeys typed for ten hours a day, it would be extremely unlikely they could produce anything legible. The purpose of the metaphor was to illustrate an extraordinarily improbable event. Over the years, Borel’s idea evolved into a more elaborate concept, and after 1970 the number of monkeys was expanded to infinity. The time involved in writing the texts also became infinitely long, so the conclusion became the certainty that the primates would reproduce absolutely all texts written by humanity, including this very article.
Before diving into the mathematical concepts behind this claim, we should clarify that we don’t need to use both an infinite number of monkeys and an infinitely long time at once. It would suffice, simply, to have infinite monkeys each pressing just one key and stopping, or a single monkey typing for infinite years to create any imaginable text.
Let’s suppose the typewriter that our sacrificed monkeys use has 50 distinct symbols. That’s enough to cover all the letters of the alphabet (without distinguishing between uppercase and lowercase), the digits 0 through 9, and a handful of punctuation marks, including the space between words. Other symbols that might appear in a text, like Greek letters or mathematical symbols, can simply be named as “alpha,” “pi,” or “sum.” This doesn’t change our analysis or its results in any way.
We also have to assume that the monkeys are trained well enough (or “untrained,” really) to type truly at random. This is hard to achieve in practice—just ask those who write algorithms to generate truly random numbers—but it’s very important for our analysis, so we’ll assume the monkey achieves it. Under these conditions, the probability of pressing a specific key is 1/50, or 2%. A text is nothing more than a sequence of characters—letters, numbers, spaces, and symbols—arranged so they make (sometimes) sense. Let’s see how much time our monkey needs to write something coherent.
Our monkey, to keep the math simple, presses one key per second. Over a workday, it will have written a text of 60*60*24 = 86,400 characters, or about 22 pages. They will almost certainly be gibberish. Let’s calculate the probability—and the time needed—for a monkey typing at that speed to write the word “neoteo.” The chance that the first key it presses is an “n” is 1/50. The probability that the second one is also an “e” is (1/50) * (1/50) = 0.0004. That means that, statistically speaking, the primate will be able to write “ne” only after pressing 2,500 keys or, equivalently, after typing for about 41 minutes. Writing “neo” is 1/50 times harder, with a probability of (1/50) * (1/50) * (1/50) = 0.000008. We can expect that after about 34 hours and 40 minutes, the syllable “neo” will appear somewhere in the roughly 40 pages written by the monkey.
Writing “neoteo” requires much more time. In fact, the probability that the exhausted monkey writes the six-letter word is only (1/50) * (1/50) * (1/50) * (1/50) * (1/50) * (1/50) = 0.000000000064. At one character per second, it would take more than 495 years to find “neoteo.”
This is enough to realize that the poor monkey will need “quite” a bit of time to produce—for example—a short story. “El dinosaurio,” written by Augusto Monterroso, whose complete text is “When he woke up, the dinosaur was still there.” is considered by many to be the shortest story ever written, with a length of 51 characters. Our little monkey, assuming it were immortal, has a chance of (1/50) multiplied by itself 51 times of writing that text. It would take 2.251799814 x 10^87 seconds, or 1.4 x 10^73 million years—a time many millions of millions of times longer than the age of the Universe—to have it ready. If we want it to write the complete works of Shakespeare, we need a much faster monkey, or we can increase the number of monkeys.
If we had a good budget and an adequate supply of bananas, we could use 7 x 10^62 monkeys, typing at a rate of one character per second. If they had started working at the very moment of the Big Bang, by now we would have (lost somewhere among the billions of billions of billions of volumes written) the text of Monterroso’s story. Of course, there would also be thousands of imperfect copies, with some extra or missing letter, or some spelling mistake. And if you searched carefully, you could find any sentence you can imagine, as long as it is 51 characters or fewer.
However, the poor monkey pounding the keyboard for infinite years is capable of writing anything imaginable. It could write, for example, the name of each of the guests staying at Hilbert’s Infinite Hotel or the Complete Works of Borges. If you set your mind to it, you could find among the pages produced the “secret formula” of Coca-Cola, or the source code of Windows Vista.
If your time is limited—after all, even Microsoft managed to write Vista’s code in a few years—you must increase the number of monkeys. Taking the idea to its extreme, infinite monkeys sitting in countless rows on the surface of an infinite planet could write whatever text you wish simply by pressing one key each. In just one second, the complete works of humanity (plus everything that can possibly be written) would be ready for you. Of course, you’d have to walk a long time among the monkeys to find what you’re looking for.
All of this serves, simply, to give us an idea of the vastness of infinity. Even though with enough time a simple monkey could write even the Unified Theory of physics, it’s always more cost-effective—in terms of time—to use reason rather than write at random. If we don’t do that, we are no better than a monkey sitting in front of a keyboard.