medium | probability |

A very innocent monkey throws a fair die. The monkey will eat as many bananas as are shown on the die, from 1 to 5. But if the die shows '6', the monkey will eat 5 bananas and throw the die again. This may continue indefinitely. What is the expected number of bananas the monkey will eat?

The pattern repeats after the first throw

4

### Method 1

The intuition is that either the die is thrown only once, or more than once. In case of only once, the expected value is $3$. In case of more than once, the expected value is $5$ + expected value of a new game. We need to find the expected value combining these two.

Let $X$ be number of bananas eaten overall and $Y$ = number shown on the first dice.

$E_1 = E[X | \text{only once}] = E[X | Y < 6] = \dfrac{1}{5}(1+2+3+4+5) = 3$

$E_2 = E[ X | \text{more than once}] = E[X | Y=6] = 5 + E[X]$

now, $E[X] = \dfrac{5}{6}\cdot E_1 + \dfrac{1}{6} \cdot E_2$

$\implies E[X] = \dfrac{5}{6} \cdot 3 + \dfrac{1}{6} \cdot (5 + E[X])$

Solving this equation gives $E[X] = 4$

Mathematically, this is called the law of total probability, i.e, $E[ E[X|Y] ] = E[X]$.

The denominator `5`

is not intuitive when solving $E_1$. For this reason, I have written the second method.

### Method 2

Here, we will solve with basic algebra, without any special techniques.

Let $X$ be the total number of banans eaten.

We know that $E[X]= P(X=1)\cdot 1 + P(X=2) \cdot 2 + \ldots$

For the first $5$ terms, the sum is simply $1/6 \cdot (1+2+3+4+5) = 15/6$

$6$th term onwards, we can see a pattern:

$P(X=6) \cdot 6 + P(X=7) \cdot 7 + \ldots$

Note that $X\ge 6$ occurs when the die is thrown again, i.e, $P(X=i) = 1/6 \cdot P(X=i - 5)$ for $i\ge 6$.

Let's substitute these values in the above equation.

$\dfrac{1}{6} [ P(X=1) \cdot 6 + P(X=2) \cdot 7 + \ldots ]$

Now, let's move the extra terms aside, to make it look more like $E[X]$

$\dfrac{1}{6} [ P(X=1) \cdot 1 + P(X=2) \cdot 2 + \ldots ] + \dfrac{1}{6} [P(X=1) \cdot 5 + P(X=2) \cdot 5 + \ldots]$

The left part is equal to $\dfrac{1}{6} E[X]$, while the right part is $1/6 \cdot 5 [$ probability of everything $] = 5/6$

$\implies E[X] = \dfrac{15}{6} + \dfrac{1}{6}E[X] + \dfrac{5}{6}$

This simplifies to $E[X] = 4$

### Method 3

Another method is to expand all the terms using linearity of expectation and then use GP sum formula.

Let $X_i$ denote the number of bananas eaten on the $i$th throw.

Thus, $E[X] = E[\sum_{i=1}^{\infty} X_i] = \sum_{i=1}^{\infty} E[X_i]$ (using linearity of expectation)

$E[X_1] = \frac{1}{6} \cdot 1 + ... + \frac{1}{6} \cdot 5 + \frac{1}{6} \cdot 5 = \frac{20}{6}$

$E[X_2] = P(\text{ first die roll was 6} ) \cdot (\text{ terms that match} E[X_1])$

$\implies E[X_2] = \dfrac{1}{6} \cdot \dfrac{20}{6}$

$\implies E[X_3] = \dfrac{1}{6^2} \cdot \dfrac{20}{6}$

This is a Geometric Progression, with $a = 20/6, r=1/6$, the sum of infinite terms will be $\dfrac{a}{(1-r)} = \dfrac{20/6}{1-1/6} = 4$

Note: This will not work for a problem that involves a state. For instance, if the monkey could cheat upto 3 times (i.e, re-throw the dice even when it is not a "6"), and the cheating-count was reset to zero when a real "6" appears, then this method will not work.