The Infinite Monkey Theorem is an urban winery operated out of the back alleys of Denver & Austin.
HAHA, Gotcha! Just kidding. Today we will talk about a famous mathematical problem, “The Infinite Monkey Theorem”. The place does exist though, I came across to their website when I was doing a research for this post.
The idea goes back to early 1900’s, it basically says if we have infinite time and infinite resources, we can create even very complex things.
Suppose you have infinite number of monkeys, infinite number of typewriters, paper, ink and time. Monkeys hit the keys randomly for 7/24, They do not get tired or they do not age. What could possibly come out from their writings?
According to our theory, this experiment might result in writing Sheakespeare sonnets, Dostoyevsky’s Crime and Punishment, or anything you can think of!
Sounds really unlikely and not realistic right? But it is not impossible. Let’s take a look at the case from mathematical perspective: Probability. Monkey has certain number of keys on the typewriters. Exactly 44 for the standard American typewriter. The probability of hitting any of them is 1/44.
Each event is independent from each other, typing “a” in one attempt and typing “z” from the next is completely independent. So, we can compute the probability of any word our little monkey is going to type. As many of you have already guessed, as the word or text gets longer, it becomes less likely to type it, but not impossible! (Considering we have unlimited resources.)
With the help of computers, it is possible to simulate such an event and leave monkeys alone. In past, some attempts have been made about random number and random document generation. If you want to learn more about them you can check out this link from Wikipedia.
I came across with this subject over my Stochastic Models course and I wanted to try it myself too! I coded it with python using random and timeit libraries.
- Random: We will use it to randomly select one letter from the alphabet
- Timeit: We will use it to record starting and ending time to see how much time it took our digital monkey to type a given text.
Since my time and computational resources are limited, I made a one word generator. Here’s our digital monkey function.
And lastly, we can run this code to see how much time it will take us to get the text we wanted. I used my name for the simplicity and also because I am a bit impatient. You can go ahead and try whatever you want!
I will leave some of the interesting applications I encountered along with other resources below. Hope it was fun and let me know if you try it yourself, it is very easy!
Here is the repo for my codes: https://github.com/semanurkps/infinite_monkey_word_generator
Infinite Monkey Number Generator: https://www.heraldic.cloud/infinite-monkey-theorem.htm