You flip a fair coin until you get two heads in a row. How many flips does it take, on average?
Most people say 4. It feels right: two flips for HH would be 4 if you somehow "double" a 50/50 wait. The real answer is 6. That gap between gut and math is why this puzzle is a favorite for learning expected value with states.
Below is a tiny Monte Carlo simulation that estimates the answer, then a short explanation of why six is exact.
The simulation
import random
def flips_until_two_heads():
streak = 0
n = 0
while streak < 2:
n += 1
if random.random() < 0.5:
streak += 1
else:
streak = 0
return n
TRIALS = 100_000
total = sum(flips_until_two_heads() for _ in range(TRIALS))
print(total / TRIALS)
Run it a few times. You should see something like 5.99 or 6.01 — close enough to 6 that the pattern is hard to miss. Increase TRIALS if you want a tighter estimate; the math below shows what the simulation is converging to.
Why the answer is 6
Track only what matters: how many heads you currently have in a row.
- State 0: no streak (start here, or after any tails).
- State 1: just got one head.
- State 2: two heads in a row — done.
Let E₀, E₁, and E₂ be the expected remaining flips from each state. E₂ = 0. From state 0 you always flip once: heads → state 1, tails → stay in 0. From state 1: heads → done, tails → back to 0.
So:
- E₀ = 1 + 0.5·E₁ + 0.5·E₀
- E₁ = 1 + 0.5·0 + 0.5·E₀
Solve those and you get E₀ = 6. You start in state 0, so the expected number of flips is 6.
The intuition that fails is treating "two heads" like "two independent waits of 2." Streaks reset. One tails throws you all the way back, which is why the wait is longer than 4.
A tiny takeaway
States beat gut estimates for streak problems. Once you name the states, the equations are almost mechanical — and the simulation is a friendly sanity check.
What's a probability puzzle where your first guess was way off? Drop it in the comments — I'd love to try simulating a few of yours.
Top comments (0)