Chapter 17
How Long Will It Take To Blow Out The Birthday Candles?
It’s your 30th birthday (congrats, by the way), and your friends bought you a cake with 30 candles on it. You make a wish and try to blow them out. Every time you blow, you blow out a random number of candles between one and the number that remain, including one and that other number. How many times do you blow before all the candles are extinguished, on average?
The Riddler, FiveThirtyEight(original post)
Solution
Let be the expected number of blows to clear candles. A single blow removes a number uniform on , so the count left is uniform on , and Claim , the th harmonic number. Suppose it holds below . Using the identity , so the claim follows by induction. For the cake, Remarkably, blowing out thirty candles takes only about four breaths on average, because the early blows tend to clear many candles at once.
The computation
Blow out the cake directly: from the candles that remain, remove a uniformly random number between and that count, repeat until none are left, and average the number of blows over many cakes. The mean matches .
import numpy as np
rng = np.random.default_rng(0)
runs = 1_000_000
total = 0
for _ in range(runs):
candles = 30; blows = 0
while candles:
candles -= rng.integers(1, candles + 1) # blow out 1..remaining
blows += 1
total += blows
print(total / runs) # ~3.995
print(sum(1 / k for k in range(1, 31))) # H_30 = 3.99499...