# So, how long would it take the monkey to type out Hamlet?

## Recommended Posts

So, given enough time, a monkey typing random words on a keyboard will eventually type out Hamlet word for word. Let us calculate the expected time it would take the monkey to do that. In my intuitive (but limited) understand of probability, I think we only need to know:

1) The number of letters in Hamlet (or characters if you want it to include spacing, punctuation etc., but excluding capitalization)

2) The average time it takes someone to type one letter, or in other words, words per minute. We must be given some leeway here because we must agree upon whether the monkey is frantically mashing the button with its fingers (not whole hands, because then the probability would always be 0) or it is typing at a rate of an average human.

3) The number of accepted buttons we will give the monkey (or words in the alphabet, depending on what we want to do)

I think given these variables, the calculation should be easy. Of course, this assumes that all keys/letters have an equal probability of being hit

Another thing we can do is calculate the probability of the monkey writing Hamlet on the first attempt. This has one less variable (2 is excluded) so it is an even easier calculation. I'm sure I could find the answer out by googling, but it is more fun this way.

So, does anyone care to add the necessary information?

##### Share on other sites

50 years. William Shakespeare's lifetime. Or 4.5 billion years, the time it took evolution to produce Shakespeare.

Edited by wtf

##### Share on other sites

I am not sure what you mean by that, but I wish that we make the calculations for ourselves. All we need is the number of characters in Hamlet (or letters, if we want to simplify) and we can agree upon the other variables as we can make them up according to what is most appropriate and it should be easy from there.

##### Share on other sites

I am not sure what you mean by that

You're joking, right?

How long did Shakespeare take to write his plays? Is he a primate or not? Am I stretching a point? Not by much. The posterior probability that a primate typed out the complete works of Shakespeare in less than 50 years is 1. It already happened.

Edited by wtf

##### Share on other sites

Are you joking?

Clearly, you understand that I mean that the monkey needs to write it independently of Shakespeare and it has nothing to do with posterior probability. You're just pulling my leg.

##### Share on other sites

So, given enough time, a monkey typing random words on a keyboard will eventually type out Hamlet word for word. Let us calculate the expected time it would take the monkey to do that. In my intuitive (but limited) understand of probability, I think we only need to know:

1) The number of letters in Hamlet (or characters if you want it to include spacing, punctuation etc., but excluding capitalization)

2) The average time it takes someone to type one letter, or in other words, words per minute. We must be given some leeway here because we must agree upon whether the monkey is frantically mashing the button with its fingers (not whole hands, because then the probability would always be 0) or it is typing at a rate of an average human.

3) The number of accepted buttons we will give the monkey (or words in the alphabet, depending on what we want to do)

I think given these variables, the calculation should be easy. Of course, this assumes that all keys/letters have an equal probability of being hit

Another thing we can do is calculate the probability of the monkey writing Hamlet on the first attempt. This has one less variable (2 is excluded) so it is an even easier calculation. I'm sure I could find the answer out by googling, but it is more fun this way.

So, does anyone care to add the necessary information?

Oh. Math. Alright. Let's take a try at this.

Hamlet has approximately 130,000 letters in it. Not counting spaces. The average typing speed is 200 characters per minute. So if the money typed it perfectly, it would take about 650,000 minutes. Or 10,833.3 hours. Or 451.4 days. Or 64.5 weeks.

Now, the money has a 1/26 chance of typing the first letter of hamlet. For the second letter, it's 676. For the third, 17,576. All in consecutive order. So there's a 1/17,576 chance the monkey will type the first 3 words in order. 26^130,000 would be the probability of it typing out the whole hamlet story. Without spaces. That, is a really really large number.

Really large.

Now what ever chance that is, we have to multiply it until it's equal to 100%. Which would be by a factor, at minimum, of 1 octillion.

1 octillion is 1,000,000,000,000,000,000,000,000,000.

That's 27 zeros. The number we're looking for has 130,000. Either way, let's say its a really fast typing monkey, and could type all of hamlet in a year. If it's odds were 1/1,000,000,000,000000000,000,000,000, it would take 1 octillion years.

The universe is 13.772 billion years old.

You would need to take at least 72,000,000,000,000,000,000(72 quintillion) times as long as the age of the universe for the monkey to have a good probability of typing out hamlet.

NOW REMEMBER.

That is if it's odds are only 26^27

The real odds are 26^130,000.

It's impossible to calculate how long it would take.

The idea that a money will do that is deceiving.

It makes some really really large numbers seem a lot sooner then they really are.

+1 if this was helpful. It took a while.

50 years. William Shakespeare's lifetime. Or 4.5 billion years, the time it took evolution to produce Shakespeare.

wtf

You're joking, right?

How long did Shakespeare take to write his plays? Is he a primate or not? Am I stretching a point? Not by much. The posterior probability that a primate typed out the complete works of Shakespeare in less than 50 years is 1. It already happened.

*sarcastic clap*

Lets see.

How long would it take you to do the math required?

##### Share on other sites

26^130,000 would be the probability of it typing out the whole hamlet story.

Correct. On the first attempt, mind you. That is not counting other characters such as punctuation, spaces and especially capitalization. But the rest of your post is baffling.

For example,

Now what ever chance that is, we have to multiply it until it's equal to 100%. Which would be by a factor, at minimum, of 1 octillion.

What do you mean by this? It is 1 in 27^130 000. I don't know what kind of equalization with 100% you're talking about.

The rest of the math is puzzling to me. It is a straightforward calculation. I don't know why you think it's impossible to calculate.

It assumes that the monkey types with regular speed. X letters per minute, constantly. This is of course, hypothetical. It doesn't need to sleep, eat, etc. You just need to factor time into the equation. Try it.

*sarcastic clap*

Lets see.

How long would it take you to do the math required?

Don't mock him. He is very good at math, but I don't know what kind of point he was trying to make with his post. Let's say that it was a joke.

##### Share on other sites

1. Correct. On the first attempt, mind you. That is not counting other characters such as punctuation, spaces and especially capitalization. But the rest of your post is baffling.

2. What do you mean by this? It is 1 in 27^130 000. I don't know what kind of equalization with 100% you're talking about.

The rest of the math is puzzling to me. It is a straightforward calculation. I don't know why you think it's impossible to calculate.

3. It assumes that the monkey types with regular speed. X letters per minute, constantly. This is of course, hypothetical. It doesn't need to sleep, eat, etc. You just need to factor time into the equation. Try it.

1. Alright. But it's a really low probability.

2. Dude. We can't assume the money will write this out in it's first try. That's ludicrous.

If you roll a dice, you have 1/6 chance of rolling a 1. If it's a perfectly fair dice, you can assume that within 6 rolls a 1 would have showed up at least once. Now it's not guaranteed, but it's probable. So you'd have to multiply the 1/6 chance by 6 to get a fair idea of how many times it would take before the monkey should have done it by that point. The monkey has 26^130,000 of typing hamlet.

3. Then do it yourself.

##### Share on other sites

I don't know what kind of point he was trying to make with his post. Let's say that it was a joke.

I don't mean to interrupt the math fest. But I am making a point about the philosophy of probability.

Suppose I say to you that it's astronomically unlikely that you exist. I point out the incredible unlikeliness that earth formed, that life developed, that your parents met, that a particular sperm cell fertilized a particular egg, that you were carried to term and lived to your current age. Why, the odds must be something like .00000000000000000000000001 or even smaller.

And you reply, "Don't be silly. Of course I exist. Here I am!"

Who is right? The person that says it's unlikely that you exist? Or the person who observes that it's certain that you exist, you're standing right there.

This is not a trivial issue in probability theory

Now if you want to calculate the odds that a randomly selected sequence of characters represents the works of Shakespeare, the mathematical arguments are valid.

But if you want to say it's astronomically unlikely that Shakespeare did what he already obviously did (modulo historical arguments that say he didn't write his own plays) you have a harder case to make.

So: A philosophical diversion, to be sure. But a joke? Not in the least. A rather serious point. Bayesians versus frequentists. https://stats.stackexchange.com/questions/22/bayesian-and-frequentist-reasoning-in-plain-english

Edited by wtf

##### Share on other sites

I don't mean to interrupt the math fest. But I am making a point about the philosophy of probability.

Suppose I say to you that it's astronomically unlikely that you exist. I point out the incredible unlikeliness that earth formed, that life developed, that your parents met, that a particular sperm cell fertilized a particular egg, that you were carried to term and lived to your current age. Why, the odds must be something like .00000000000000000000000001 or even smaller.

And you reply, "Don't be silly. Of course I exist. Here I am!"

Who is right? The person that says it's unlikely that you exist? Or the person who observes that it's certain that you exist, you're standing right there.

This is not a trivial issue in probability theory

Now if you want to calculate the odds that a randomly selected sequence of characters represents the works of Shakespeare, the mathematical arguments are valid.

But if you want to say it's astronomically unlikely that Shakespeare did what he already obviously did (modulo historical arguments that say he didn't write his own plays) you have a harder case to make.

So: A philosophical diversion, to be sure. But a joke? Not in the least. A rather serious point. Bayesians versus frequentists. https://stats.stackexchange.com/questions/22/bayesian-and-frequentist-reasoning-in-plain-english

Shakespeare, does not count as the aforementioned monkey.

##### Share on other sites

Suppose I say to you that it's astronomically unlikely that you exist. I point out the incredible unlikeliness that earth formed, that life developed, that your parents met, that a particular sperm cell fertilized a particular egg, that you were carried to term and lived to your current age. Why, the odds must be something like .00000000000000000000000001 or even smaller.

Now that you mention it, yes, I have thought about this. It reminds me of Creationists saying ''what are the odds that the Earth was formed exactly the way it was?'' This question is moot, because all the other possibilities of how it could have been formed are equiprobable. So, let's say that you must throw a die 1000 times in a row and record the results. Upon witnessing the results, you then exclaim ''what were the odds that I would get this exact same sequence?'' It makes no sense, because all other results yielded the same probability of 6^1000 and one of them had to happen. Of course, another question is how well earth would have worked out were it formed in a different way and is it possible that we, or the same ''we'' would exist on it, but this is a completely different matter alltogether.

The same logic applies for questions like ''what were the odds that you would have these exact personality traits'' or ''have this exact name and do this specific thing at this time'' etc.

Who is right? The person that says it's unlikely that you exist? Or the person who observes that it's certain that you exist, you're standing right there.

Surely, the statement ''it's unlikely that you exist'' is clumsy linguistics. It may or may not have been unlikely that he would exist prior to his existance, but it is certain once it has happened. It is, as you mentioned, a posterior probability once it has happened.

But if you want to say it's astronomically unlikely that Shakespeare did what he already obviously did (modulo historical arguments that say he didn't write his own plays) you have a harder case to make.

No, I don't want to say that. The thread was merely meant to deal with basic mathematical probability. Saying that it was likely or unlikely that Shakespear would have written Hamlet is difficult as you have to account for his mental traits and age of when you want to say this for.

I don't feel like giving probability (other than 1) for posterior cases makes sense. In other words, saying that something that happened is unlikely is a clumsier and less precise way of saying that it WAS unlikely prior to it happening. But you could argue they are the same thing.

So: A philosophical diversion, to be sure. But a joke? Not in the least.

It was offtopic, but sure, I welcome it.

##### Share on other sites

It was offtopic, but sure, I welcome it.

Glad I was able to express myself more clearly. I'll leave y'all to the calculations.

Did you know that under laboratory conditions, coin flips are not random?

People make hidden philosophical assumptions about probabilities, without even realizing it. There's nothing random about a coin flip.

##### Share on other sites

I know that coin flips are not random. We even had a long talk about it in another thread. Basically, they are AS GOOD as random to us, because we do not posses the brainpower to predict their force, spin, velocity etc. They are not random at all.

As for the thread, I will now attempt to calculate it. Do make sure it is correct. If you have any further comments on this philosophy of probability, do comment.

Alright, back on topic.

2. Dude. We can't assume the money will write this out in it's first try. That's ludicrous.

If you roll a dice, you have 1/6 chance of rolling a 1. If it's a perfectly fair dice, you can assume that within 6 rolls a 1 would have showed up at least once. Now it's not guaranteed, but it's probable. So you'd have to multiply the 1/6 chance by 6 to get a fair idea of how many times it would take before the monkey should have done it by that point. The monkey has 26^130,000 of typing hamlet.

You may be misunderstanding something here. There were two questions. One was how long it is expected for the monkey to type out Hamlet and another was what are the odds that it would type it out on the first attempt. You figure of 1 in 26^130 000 answered the latter correctly (assuming that punctuation, spacing etc. wasn't needed and that the monkey only had access to the letters of the alphabet and not the other keyboard keys). There was no need to equate that to 100%, whatever that means. It answered the question.

3. Then do it yourself.

I just tried to do it and I realized I can't, which is a shame. I'm not sure how you factor time into the equation and get the expected time of the monkey's success.

It is the same as asking ''What is the expected amount of time it would take you to flip 5 heads in a row?'' only with higher figures. It seems simple, but I realize that I don't know how to solve it. Note that time refers to physical time and not the number of coin flips.

##### Share on other sites

So, given enough time, a monkey typing random words on a keyboard will eventually type out Hamlet word for word. Let us calculate the expected time it would take the monkey to do that. In my intuitive (but limited) understand of probability, I think we only need to know:

1) The number of letters in Hamlet (or characters if you want it to include spacing, punctuation etc., but excluding capitalization)

2) The average time it takes someone to type one letter, or in other words, words per minute. We must be given some leeway here because we must agree upon whether the monkey is frantically mashing the button with its fingers (not whole hands, because then the probability would always be 0) or it is typing at a rate of an average human.

3) The number of accepted buttons we will give the monkey (or words in the alphabet, depending on what we want to do)

I think given these variables, the calculation should be easy. Of course, this assumes that all keys/letters have an equal probability of being hit

Another thing we can do is calculate the probability of the monkey writing Hamlet on the first attempt. This has one less variable (2 is excluded) so it is an even easier calculation. I'm sure I could find the answer out by googling, but it is more fun this way.

So, does anyone care to add the necessary information?

There is no information to offer.

Except to say that your opening claim is patently false.

A group of a million monkeys would be very fortunate to comprise a Dr. Seuss book in a century of typing. Hamlet or any other piece of literature of even remotely close volume and complexity is out of the question.

This thread needs to go to Speculation.

At best.

LOL

##### Share on other sites

I just tried to do it and I realized I can't, which is a shame. I'm not sure how you factor time into the equation and get the expected time of the monkey's success.

It is the same as asking ''What is the expected amount of time it would take you to flip 5 heads in a row?'' only with higher figures. It seems simple, but I realize that I don't know how to solve it. Note that time refers to physical time and not the number of coin flips.

Well, it's not perfect, but a rough way to do it is equate it to 100%.

The probability of flipping heads 5 times in a row is 1/32.

Obviously, any order of flips is 1/32.

But to figure out the amount of time it would take you to flip 5 coins in a row and have each land on heads is simple enough in my opinion.

First, assume each coin flip will take 1 second. To flip 5 coins, it would take 5 seconds.

Now accounting for the time it would take you to pick up the coins let's say it takes 10 seconds to pick up the coins. Each flip takes 15 seconds. Now obviously, there's a 10 second difference now, because you would start with all coins in your hand, and all coins in your hand when you ended. So just subtract 10 seconds to the final figure.

Either way, you can assume that in 32 total runs, you would have flipped 5 heads in a row at least once.

Obviously, this is wrong. You can't guarantee this. Some things would have showed up twice. But lets just call it approximate.

It would take 470 seconds to run this 32 times.

In 32 times, it can be assumed that 5 heads would appear once. Probably not, but you get the idea.

But that's how I tried to calculate the monkey scenario.

I took the probability fraction. 1/26^130,000 and multiplied the denominator by the amount of time.

But since the denominator was so frickin large, I took a much smaller number. 1 Octillion. Which is way way way way way way way less. Octillion is only 10^26. We need 2.6 ^ 130,001.

So the amount of time is 1 year(rounding down. Let's say the monkey types fast and if he typed constantly he could get it done in 1 year.) It would take 2.6^130,001 years. And even then, its just that would be the estimated amount of time before he even had a remote chance of having typed it.

There is no information to offer.

Except to say that your opening claim is patently false.

A group of a million monkeys would be very fortunate to comprise a Dr. Seuss book in a century of typing. Hamlet or any other piece of literature of even remotely close volume and complexity is out of the question.

This thread needs to go to Speculation.

At best.

LOL

Infinity, is a long time.

After an infinite amount of time, the monkeys would.

Edited by Raider5678

##### Share on other sites

There is no information to offer.

Except to say that your opening claim is patently false.

A group of a million monkeys would be very fortunate to comprise a Dr. Seuss book in a century of typing. Hamlet or any other piece of literature of even remotely close volume and complexity is out of the question.

This thread needs to go to Speculation.

At best.

LOL

This makes me think that you don't understand probability. The monkey, given an infinite amount of time will certainly (or almost certainly, as was correctly noted in another thread) produce every literary work ever made. We are trying to calculate the expected amount of time it would take.

Please do not post if you have nothing of value to contribute.

Sorry, crosspost. I will check your calculation, Raider.

##### Share on other sites

After an infinite amount of time, the monkeys would.

Actually that's true with probability 1, but it could still happen. Just as you can toss infinitely many coins and have them all come up heads. The probability is zero, but it could still happen. After all, the probability of ANY particular outcome is zero.

Say we let the monkeys type away for an infinite amount of time. We look at their exact output. The probability of that exact output is ... zero!! It's no more likely than the complete works of Shakespeare!

The psychological reason we don't appreciate this point is that we are comparing the probability of gibberish, which is 1; to the probability of the works of Shakespeare, which is zero.

But whatever specific outcome does happen to occur, the probability of that exact outcome was also zero.

Edited by wtf

##### Share on other sites

Well, it's not perfect, but a rough way to do it is equate it to 100%.

The probability of flipping heads 5 times in a row is 1/32.

Obviously, any order of flips is 1/32.

But to figure out the amount of time it would take you to flip 5 coins in a row and have each land on heads is simple enough in my opinion.

First, assume each coin flip will take 1 second. To flip 5 coins, it would take 5 seconds.

Now accounting for the time it would take you to pick up the coins let's say it takes 10 seconds to pick up the coins. Each flip takes 15 seconds. Now obviously, there's a 10 second difference now, because you would start with all coins in your hand, and all coins in your hand when you ended. So just subtract 10 seconds to the final figure.

Either way, you can assume that in 32 total runs, you would have flipped 5 heads in a row at least once.

Obviously, this is wrong. You can't guarantee this. Some things would have showed up twice. But lets just call it approximate.

It would take 470 seconds to run this 32 times.

In 32 times, it can be assumed that 5 heads would appear once. Probably not, but you get the idea.

But that's how I tried to calculate the monkey scenario.

I took the probability fraction. 1/26^130,000 and multiplied the denominator by the amount of time.

But since the denominator was so frickin large, I took a much smaller number. 1 Octillion. Which is way way way way way way way less. Octillion is only 10^26. We need 2.6 ^ 130,001.

So the amount of time is 1 year(rounding down. Let's say the monkey types fast and if he typed constantly he could get it done in 1 year.) It would take 2.6^130,001 years. And even then, its just that would be the estimated amount of time before he even had a remote chance of having typed it.

Infinity, is a long time.

After an infinite amount of time, the monkeys would.

They would not.

Since if they were to omit or incorrectly type even one word, their effort had failed. Unless you wish to begin allowing caveats and exceptions and whatnot.

I should rephrase to say the chances are so infinitely small that it equates to a zero chance. I'm not sure you could come up with something having a lesser chance of happening!

This article does some impressive number crunching on the Infinite Monkey Myth.

http://wmbriggs.com/post/2409/

##### Share on other sites

Look. Pretty much the same thing I was doing.

Except.

He's wrong.

He's so frickin wrong.

He's saying the works of Shakespeare is something special. But instead, it's the same as every other 6,000,000 character long piece of work.

And in an infinite amount of time. INFINITE. Never ends.

It will go on, forever and ever.

Every single 6 million character long document they make, has an impossible chance of being made according to him.

Because "the chances of this particular thing being made is impossible."

Except, it was made. Each document the monkey makes is impossible, yet it's still there.

There's nothing special about Shakespeare's works. It's just another document.

Eventually, it would happen in an INFINITE amount of time.

Edited by Raider5678

##### Share on other sites

Actually that's true with probability 1, but it could still happen.

There is a typo here somewhere.

And concerning the rest of the post, don't you mean that it will almost certainly happen, rather than almost never happen?

They would not.

Since if they were to omit or incorrectly type even one word, their effort had failed. Unless you wish to begin allowing caveats and exceptions and whatnot.

I should rephrase to say the chances are so infinitely small that it equates to a zero chance. I'm not sure you could come up with something having a lesser chance of happening!

This article does some impressive number crunching on the Infinite Monkey Myth.

http://wmbriggs.com/post/2409/

Then you do not understand infinity. Given infinite time, everything will certainly happen (or almost certainly as pointed out by wtf).

You did a quick google search and misunderstood the text.

The infinite monkey theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type a given text, such as the complete works of William Shakespeare. In fact the monkey would almost surely type every possible finite text an infinite number of times. However, the probability that monkeys filling the observable universe would type a complete work such as Shakespeare's Hamlet is so tiny that the chance of it occurring during a period of time hundreds of thousands of orders of magnitude longer than the age of the universe is extremely low (but technically not zero).

Quote from wikipedia. Note that the last part deals with finite number of monkeys and finite amount of time, which is what you may have read somewhere in that article. For example, an infinite amount of monkeys would produce Hamlet in simply the time it takes one of them to write Hamlet. This is not a myth. I propose you think twice or at least read up on it.

Edited by Lord Antares

##### Share on other sites

Quote from wikipedia. Note that the last part deals with finite number of monkeys and finite amount of time, which is what you may have read somewhere in that article. For example, an infinite amount of monkeys would produce Hamlet in simply the time it takes one of them to write Hamlet. This is not a myth. I propose you think twice or at least read up on it.

Have you checked my calculations yet?

##### Share on other sites

Yes, but the numbers don't make sense to me. I don't know how you arrived at a few of them and at the estimate of time. It doesn't seem obvious to me. Some of it is correct, but I'm not sure about the whole equation.

Maybe I'm missing something.

Edited by Lord Antares

##### Share on other sites

Yes, but the numbers don't make sense to me. I don't know how you arrived at a few of them and at the estimate of time. It doesn't seem obvious to me. Some of it is correct, but I'm not sure about the whole equation.

Maybe I'm missing something.

What is confusing?

##### Share on other sites

Every starting letter could be the first letter of a specific string of 130000 characters. The probability of that is 1 in 26^130000 or 1 in 10^(130000.log26)=10^184000.

The probability that a letter is not the first of the collected works of Shakespeare is (1-1/10^184000). If we repeat this for 10^184000 times, at eg 1 letter per second, it takes 10^184000 seconds.

The probability of not writing the collected works of Shakespeare is

$(1-\frac{1}{10^{184000}})^{10^{184000}}$

I'm a bit rusty on my statistics and short on time. If you are interested in knowing the probability of writing it in a certain amount of time or the amount it would take to be eg. 95% sure that you would have typed it, you need to look up binomial or poisson distributions.

Edit: ok a quick search yielded that the limit of

$(1-\frac{1}{n})^{n}$

is 1/e or 37 %

so after about 10^184000 seconds, you would have 63% chance of randomly typing the collected works of Shakespeare.

Edited by Bender

##### Share on other sites

Thank you for your input. I didn't realize it was a somewhat complicated issue. I will have to look up what you recommended.

I have run into this 95% certainty thing before in statistics. I have read that a 95% certainty in statistics is considered to be statistically sound and likewise, a 5% certainty unsound.

What is the significance of these numbers? Surely, this is just an arbitrary, generally agreed upon limit. There is no other significance of the number, right?