You play a game with four balls: One ball is red, one is blue, one is green and one is yellow. They are placed in a box. You draw a ball out of the box at random and note its color. Without replacing the first ball, you draw a second ball and then paint it to match the color of the first. Replace both balls, and repeat the process. The game ends when all four balls have become the same color. What is the expected number of turns to finish the game?

## Solution

A possible “situation” is a numerical description of the division of the balls in to same-color groups. With $4$ balls we can label the possible situations $[1,1,1,1]$ (the situation at the start), $[2,1,1]$, $[2,2]$, $[3,1]$, and $[4]$ (the situation at the end).

Each situation has a readily-determined probability of being followed by each other situation. For example, from $[2,1,1]$ to remain in the same situation you can get both of the same-colored balls ($1/2 \times 1/3$, or $1/6$ chance of that), or you can get one of the loners and then one of the two same-colored balls ($1/2 \times 2/3$, or $1/3$ chance of that), for a total probability of $1/2$. Here are all the cases:

$[1,1,1,1]$: Probability $1$ of $[2,1,1]$.

$[2,1,1]$: Probability $1/6$ of $[2,2]$, $1/2$ of $[2,1,1]$, and $1/3$ of $[3,1]$.

$[2,2]$: Probability $1/3$ of $[2,2]$, and $2/3$ of $[3,1]$.

$[3,1]$: Probability $1/2$ of $[3,1]$, $1/4$ of $[2,2]$, and $1/4$ of $[4]$.

Where $A$, $B$, $C$, and $D$ are the expected number of turns to yield $4$ starting with each of these situations, in the order just listed, then, we have the following system of equations:

$A = 1 + B$

$B = 1 + B/2 + C/6 + D/3$

$C = 1 + C/3 + 2D/3$

$D = 1 + C/4 + D/2$

Tedious minutes later, or in an instant after entering the equations into an online system of equations solver, we find that $A$, $B$, $C$, and $D$ are $9$, $8$, $7$, and $11/2$. So we expect the game to take $9$ turns.

Which, interestingly enough, is $(4-1)^2$. Hmmm . . .

## Extra Credit

What if there are more balls and more colors?

Let’s ask the question, given a particular color, on average how many turns does it take for that color to win, given that it does win? This will answer the puzzle question, because all colors are alike in this respect.

Let $E_i$ be the average number of turns from now for the color to win when currently there are $i$ balls of that color. Then, where $B$ is the number of Balls:

To get an expression for $E_1$, we add $1$ (for the first turn) to the weighted average of the expectations of the possible outcomes of the first turn that are consistent with the color winning (namely, staying at $1$ and going to $2$). The weights are the conditional probabilities that the outcomes occur given that we are ultimately going to win. The probability of $A$ conditional on $B$ is:

In this case, the probability that we stay put at $1$ conditional on our winning is the unconditional probability that we stay put now times the probability that in that case we win, divided by the unconditional probability that from this situation we win:

And the probability that we move to $2$ conditional on our winning is:

So,

Solving,

For every intermediate $i$, the expectation $E_i$ is $1$ plus a function of the two neighboring expectations $E_{i-1}$ and $E_{i+1}$ and of $E_i$ itself, weighted by how likely it is to color one more ball, or one fewer, or remain at $i$ on the next turn, again conditional on our winning.

The probability that we’ll now move to $i-1$, given that we’ll go on to win is:

The probability of now moving to $i+1$, given an eventual win, is:

And the probability of staying put given a win is:

Therefore,

Rearranging,

Let $\Delta_i = (i+1)E_{i+1} - iE_i$. Remembering that $E_1 = E_2 + \frac{B}{2}$, we know that,

And remembering that $E_B = 0$,

That double-sum can be simplified to a single sum, by putting in the numerator of the summed fraction an expression for how many times the original fraction would occur in the expansion of the double-sum:

Thus,

And for arbitrary $i$,

Calling the second addend $X$,

If there are $B$ colors as well as balls, the expected length of the game is $E_1$. If there are $C$ colors evenly distributed among the balls, the expectation is $E_{B/C}$.

For a game with 100 balls, the graph below shows how the expected number of turns until a color wins, assuming it will, depends on how many balls are currently of that color. (Perhaps surprisingly, $E_{99}$ is approximately $419$.)

By the way, it’s possible to replace the sum in the above explicit expression for $E_i$ with what look like more closed-form expressions employing the digamma function or the harmonic numbers, but any apparent advantage of the simple notation is illusory, given how those functions are defined.

See this similar and more concise solution by Sawyer Tabony.