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 we get:

So with a fair coin, the answer is 2. If the coin turns up with , the expected number of coin-flips is .

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