Given a possibly-unfair coin, what’s the expected number of coin-flips until you get heads?

The answer isn’t surprising, but proving it to myself was harder than I expected.

Let’s get rigorous with random variables.

So, choose some example probababilities, then write the general formula.

Now the expected value…

Now let’s take a break and fool around with the geometric series formula. Here it is:

Take the derivative.

Cool, that formula just saved the day.

Substituting $k = 1 - p$ we get:

So with a fair coin, the answer is 2. If the coin turns up with $p = \frac{3}{4}$, the expected number of coin-flips is $\frac{4}{3}$.

This is a special case of the negative binomial distribution, by the way.