Skip to content
Vamshi Jandhyala

Books · The Riddler

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 TnT_n be the expected number of blows to clear nn candles. A single blow removes a number uniform on {1,,n}\{1,\dots,n\}, so the count left is uniform on {0,1,,n1}\{0,1,\dots,n-1\}, and Tn=1+1nj=0n1Tj,T0=0.T_n = 1 + \frac1n \sum_{j=0}^{n-1} T_j, \qquad T_0 = 0. Claim Tn=Hn=1+12++1nT_n = H_n = 1 + \tfrac12 + \cdots + \tfrac1n, the nnth harmonic number. Suppose it holds below nn. Using the identity j=1n1Hj=nHn1(n1)\sum_{j=1}^{n-1} H_j = n H_{n-1} - (n-1), 1+1nj=0n1Hj=1+nHn1(n1)n=Hn1+1n=Hn,1 + \frac1n \sum_{j=0}^{n-1} H_j = 1 + \frac{n H_{n-1} - (n-1)}{n} = H_{n-1} + \frac1n = H_n, so the claim follows by induction. For the cake, T30=H303.995.T_{30} = H_{30} \approx \boxed{3.995}. 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 11 and that count, repeat until none are left, and average the number of blows over many cakes. The mean matches H30H_{30}.

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...