Infinite Monkeys
Posted by phil on 27 Apr 2004 at 04:20 pm | Tagged as: Uncategorized
So, it’s been shown that it may take a bit more than infinite monkeys on infinite typewriters to spontaneously produce the works of Shakespeare. However, all this study showed was that monkeys are not truly random animals. Apparently they have an affinity for the letter ’s’.
So that got me thinking: what if we used a source that was truly random? Are the works of Shakespeare contained in the irrational number e? Naturally, it is infinite. Not only that, but it contains no repeated patterns. So if you were to search for words, would you find them? The likelihood of finding even a single sentence in a random string of 10,000 letters is fairly low. But there’s no end to infinity. For each segment of numbers in e that could contain some Shakespeare, the probability is very low that it would. Vanishinly low. But when a nonzero probability is multiplied by infinity, the result is a certainty. Not only would you get Shakespeare, you would get Shakespeare repeated an infinite number of times.
Not that I can test this theory, but I cooked up a little script to play with the immensity of the idea: (using random letters, not e)
<br />
#!/usr/bin/perl<br />
$target = "the";<br />
<br />
for($i=0; !$done; $i++)<br />
{<br />
$randomChar = int(rand(25));<br />
@word[$i % 3] = chr($randomChar + 97);<br />
$word = @word[($i % 3) - 2] . @word[($i % 3) - 1] . @word[$i % 3];<br />
<br />
if($word eq $target)<br />
{<br />
$done = 1;<br />
}<br />
}<br />
<br />
print "Found $target in $i letters.
";
Now the word ‘the’ is the most common word in English, but to a random string of letters, they are all the same. The results were not too high; it could usually find it in under 10,000 letters. Occasionally it found it in under 500.
So I decided to step things up just a bit. How long would it take to find the word ‘hamlet’?
/>
It’s still going. I’ll see if it finds it while I’m at work.