Conditional probability for a monkey to randomly write a sentence

364 Views Asked by At

We all know the statement that a monkey, typing random keys, given enough time, will type anything we want. Say what I want is the sentence: "This is cool".

There are 12 characters, if the monkey's keyboard has 30 keys (the actual number is irrelevant), there will be $\frac{1}{30^{12}}$ probability to write that sentence.

Let's change the problem, now I am going to assume that, as soon as the monkey types the first correct letter, the "T" (let's forget about upper/lower case) a special software on the keyboard will automatically type a "T" before each new keystroke, so that, as soon as the monkey types the "h", she will actually be typing "Th". Then, the software will automatically pre-pend "Th" to any new keystroke, so that, as soon as the monkey types an "i", we will see "Thi", at which point the software will always prepend "Thi" and so on.

This goes on until we get "This is coo" which is pre-pended to any new keystroke, and when the monkey randomly hits an "l" I have the sentence "This is cool".

My question is, what is the probability that the monkey will type "This is cool" if she types on a keyboard with this special software installed?

My intuition is suggesting something similar to $\frac{1}{12*30}$ but I am not sure if that is correct, or how to prove it.

In particular, I believe in the first case we should on average wait for $\frac{1}{30^{12}}$ keystrokes, how long should we wait in the second case?

1

There are 1 best solutions below

7
On

The question about the probability isn't well-defined because you haven't specified the number of attempts. In the first scenario, without the special software, you stated the probability for a single attempt; this probability is the same in the second scenario because the software isn't of any help in a single attempt.

However, the number you suggested does relate to the solution: It's the reciprocal of the expected number of keystrokes. Each letter is typed correctly with probability $\frac1{30}$, so the expected number of keystrokes to get one letter right is $30$. Once she gets a letter right, the letters she types effectively become attempts at the second letter, as the software prepends the correct first letter. Thus, the probability to get the second letter right is again $\frac1{30}$, and the expected number of keystrokes to get it right is again $30$. This works the same for all $12$ letters, so by linearity of expectation the expected total number of keystrokes is

$$12\cdot30=360\;.$$

This is all assuming that you're only counting the monkey's keystrokes. Since you write that the software “types” the correct letters, these might also be counted as keystrokes. In that case, each attempt at the $k$-th letter would require $k$ keystrokes, so the expected total number of keystrokes would be

$$ 30\sum_{k=1}^{12}k=\frac{30\cdot12\cdot(12+1)}2=2340\;. $$