# What would be the maximum number of guesses for a random number between 1 and 9?

How many guesses could someone get wrong if they were trying to guess a number between 1 and 9, with the integer always changing with each attempt?

For example:

If a random number generator had the values set between 1 and 9, and with every click of the mouse the RNG chose the number. How many times could one guess incorrectly and how many times could a person guess wrong? Is there even such a way to figure this out?

Thanks.

• you should clarify this more. – Irrational Person Jan 6 '15 at 4:52

You could theoretically guess wrong an arbitrarily large number of times.

The probability that you guess wrong $n-1$ times and get it right on the $n^\text{th}$ time is

$$P(\text{takes } n \text{ guesses}) = \frac{1}{9}\left(\frac{8}{9}\right)^{n-1}$$

We can find the expected value of the number of guesses it will take to get it right as an infinite sum:

$$E(\text{number of guesses})=P(\text{takes } 1 \text{ guess})+2P(\text{takes } 2 \text{ guesses})+3P(\text{takes } 3 )+\cdots$$

This is

$$E=\frac{1}{9}\left(1+2\left(\frac{8}{9}\right)+3\left(\frac{8}{9}\right)^2+\cdots\right)$$

$$9E=1+2\left(\frac{8}{9}\right)+3\left(\frac{8}{9}\right)^2+4\left(\frac{8}{9}\right)^4+\cdots$$

$$9E\left(\frac{8}{9}\right)=\frac{8}{9}+ 2\left(\frac{8}{9}\right)^2 +3 \left(\frac{8}{9}\right)^3+\cdots$$

Notice the similarity in denominators of the above two equations. We can subtract $8E$ from $9E$ to get

$$9E-8E=1+\frac{8}{9}+\left(\frac{8}{9}\right)^2+\cdots$$

This is just a geometric series, and we get

$$E=9$$

It's actually no coincidence that this is the reciprocal of the probability of getting any given guess correct. These situations in which you do repeated things with the same probability of success are called Bernoulli trials. In general, for Bernoulli trials in which the probability is $p$, the expected number of trials necessary to get the first success is $1/p$. You can prove this using the same argument above (the series, by the way, is called an arithmetico-geometric series).

As Ross Millikan points out, if we want to find the number of wrong guesses before the first correct one, then we can simply subtract $1$ from our answer above. This expected value is thus $\boxed{8}$. For a general repeated-Bernoulli-trials situation, it'd be $(1-p)/p$.

• As I read the question, it asks for the expected number of wrong guesses, so you should not count the last correct one. That subtracts one from your answer. – Ross Millikan Jan 6 '15 at 5:07
• @RossMillikan Thanks, will fix. EDIT: fixed – Zubin Mukerjee Jan 6 '15 at 5:09

The numer of wrong guesses may be arbitrary large. In the case from your example $$P(W=n)=\left(\frac89\right)^n\frac19,$$ where $W$ means the numer of wrong guesses.

• @RossMillikan The earlier one was not necessarily wrong. The stopping condition is not specified in the question (and that is to blame for the confusion, in my opinion). I think Przemysław was (perhaps unknowingly) thinking of the probability of getting every guess wrong when the game has been played $n$ times. – M. Vinay Jan 6 '15 at 5:12

Let the event Y be guessing the successful number. Then we can say that Y follows a geometric distribution:

http://en.wikipedia.org/wiki/Geometric_distribution

And I think it is safe to say that a person could make any countable number of incorrect guesses. Because the number changes after each guess, each guess is an independent event.

That wikilink has all the information about calculating E(Y) and P(Y), so I won't reproduce those formulas here.

Let $E$ be the expected number of wrong guesses. With probability ${1\over9}$ the first guess is correct. With probability ${8\over9}$ the first guess is wrong, and $E$ more wrong ones are to be expected. It follows that $$E={1\over9}\cdot 0+{8\over9}\cdot(1+E)\ ,$$ from which we deduce that $E=8$.