You have 3 cakes. Everytime you eat one, there's 17% chance the number of cakes is reset to 3. Find average number of cakes eaten?

Let $f(n)$ be the expected number of cakes left to eat when there are $n$ cakes remaining. If there is one cake remaining, we eat it and either have no cakes remaining with probability $0.83$, or go back to three cakes with probability $0.17$. We thus have:

$$f(1) = 1 + 0.17 f(3)$$

Similarly, if there are two cakes remaining, we eat one and either go to one cake with probability $0.83$, or go back to three cakes with probability $0.17$. We thus have:

$$f(2) = 1 + 0.83 f(1) + 0.17 f(3)$$

A similar reasoning can be applied to the case in which we have three cakes remaining:

$$f(3) = 1 + 0.83 f(2) + 0.17 f(3)$$

Plugging $f(1)$ and $f(2)$ into the last equation, we find:

$$f(3) = 1 + 0.83 \left( 1 + 0.83 \left( 1 + 0.17 f(3) \right) + 0.17 f(3)\right) + 0.17 f(3) \iff f(3) \approx 4.405$$


Here's a technique that is efficient even for large values of the number $n_0$ of cakes we start with and reset to (in the given problem, $n_0 = 3$).

Let $E(n)$ be the expected number of cakes needed to finish when there are $n$ cakes remaining---then, we're looking for the value of $E(n_0)$---and let $p > 0$ be the probability of reset after each turn (in our case $p = 0.17$). The replacement rule tells us that $$\phantom{(\ast)} \qquad E(n + 1) = 1 + p E(n_0) + (1 - p) E(n) . \qquad (\ast)$$ Replacing $n$ with $n + 1$ in this relation, subtracting the original equation, and rearranging gives the linear recurrence relation $$E(n + 2) - (2 - p) E(n + 1) + (1 - p) E(n) = 0.$$ Substituting the standard ansatz $E(n) = a r^n$ and factoring gives $r = 1, 1 - p$, so the general solution is $$\phantom{(\ast\ast)} \qquad E(n) = A + B (1 - p)^n . \qquad (\ast\ast)$$ We can substitute $n = 0$ in $(\ast)$ and $n = 0, 1$ in $(\ast\ast)$ and solve for $A, B$, and substituting the result ($A = E(n_0) + \frac{1}{p}$, $B = -A$) yields $$E(n) = \frac{(p E(n_0) + 1) [1 - (1 - p)^n]}{p} .$$ Evaluating at $n = n_0$ and solving gives the desired quantity, $E(n_0)$. $$E(n_0) = \frac{1}{p} [(1 - p)^{-n_0} - 1] .$$ In our case, $n_0 = 3, p = 0.17$, and substituting gives $$E(3) = 4.40531\!\ldots ,$$ which agrees with the result of your Monte Carlo simulation to within $0.01$.


Let $k$ be the expected number of cakes eaten when you start from a pile of three cakes. We're going to come up with a formula for $k$ in terms of itself, which we can then solve for the explicit value of $k$.

You have three cakes. One of four things will happen

  • You eat one, and the cakes respawn. This happens $.17$ of the time, and results in a final count of $k+1$ cakes eaten (the one you just ate plus the $k$ expected from repeating the experiment.) (Yes, this is legal!)

  • You eat two, and then the cakes respawn. This happens $(.83)(.17)$ of the time and results in a final count of $k+2$ cakes eaten.

  • You eat three, and then the cakes respawn. This happens $(.83)^2(.17)$ of the time and results in a final count of $k+3$ cakes eaten.

  • You eat three and are done. This happens $(.83)^3$ of the time and results in three cakes eaten.

Therefore, by the laws of expectation, we have $$k=(.17)(k+1)+(.83)(.17)(k+2)+(.83)^2(.17)(k+3)+(.83)^3\cdot 3$$ $$k=.428213k+2.5189$$ $$k=4.40531$$

at least to the precision of my calculator.

Tags:

Probability