The Infinite Monkey Theorem

Tivadar Danka small portrait Tivadar Danka
The Infinite Monkey Theorem

Understanding math will make you a better engineer.

So, I am writing the best and most comprehensive book about it.

The number of atoms in the observable universe is approximately 108010^80.

Randomly smashing my keyboard and reproducing this tweet has a chance of 11 in 256280256^280. This is infinitesimally small. Yet, if I keep trying long enough, it will happen with probability 11.

Let me explain why.

(This post was originally posted in a Twitter thread, which why I am talking about tweets here.)

Probability of reproducing a given tweet by randomly typing

First things first. If we generate a random string of 55 characters, what is the probability of getting "hello"?

Assuming only ASCII characters, we have 256256 options in total.

Thus, each character has a 1/2561/256 probability of hitting the right one.

Probability of matching a given character

If we are truly random in our selections, each choice is independent of the others.

Thus, hitting every character has a probability of 12565 \frac{1}{256^5} .

Probability of matching a given string

Now imagine randomly generating a tweet, which is a 280280-character string.

Following the same logic, matching a given tweet has a probability of p=1256280p = \frac{1}{256^{280}}.

It's beyond comprehension how small this is. Why then it is a certainty that I'll hit this if I keep trying?

Probability of matching a 280-character string

Let's say I am randomly generating tweets one at a time.

What's the probability that I'll succeed in matching on the n-th attempt?

Success per attempt has a probability pp, while failure has (1p)(1-p). Thus, we can calculate the odds of (n1)(n-1) failures and one success.

Probability of matching the 280-character string for the n-th attempt

What is the probability that I'll randomly reproduce my first tweet at some point?

Well, I can be successful either on the first attempt, or the second, or the third, and so on...

Thus, we can sum up the probabilities to get the chance of eventual success.

Probability of matching the 280-character string eventually

Surprise: the probability of success is 11. (We used the famous closed formula for the geometric series.)

This is why a monkey smashing a typewriter will eventually reproduce the complete works of Shakespeare.

How much you have to wait is a question for another day.

Probability of matching the 280-character string eventually

Having a deep understanding of math will make you a better engineer.

I want to help you with this, so I am writing a comprehensive book that takes you from high school math to the advanced stuff.
Join me on this journey and let's do this together!