Unexpected coin flip experiment
In this post, I explore a seemingly straightforward coin flip game between two players. Interestingly, the intuitive approach fails when validated with a Monte Carlo simulation.
Interesting idea from this X post by @littmath:
Flip a fair coin 100 times — it gives a sequence of heads (H) and tails (T). For each HH in the sequence of flips, Alice gets a point; for each HT, Bob does, so e.g. for the sequence THHHT Alice gets 2 points and Bob gets 1 point. Who is most likely to win?
If we pause to analyze, it might initially seem that Alice has the upper hand. Consider a perfect scenario: if the sequence were all heads (HHHHHHHHHH), Alice could rack up to 9 points out of 10 flips. On the flip side (pun intended), in a mixed sequence like HTHTHTHTHT, Bob would only manage to score 5 points out of 10. This reasoning suggests Alice might have a better chance of winning, right?
But the Monte Carlo simulation says otherwise. With N=1M iterations, Bob comes out ahead:
import numpy as np
np.random.seed(0x1B)
N = 1_000_000
bob_wins = 0
alice_wins = 0
for i in range(N):
flips = np.random.randint(0, 2, size=100) # 0: head, 1: tail
flips_diff = np.diff(flips) # 1 for TH, -1 for HT, 0 otherwise
points_alice = np.sum((flips_diff == 0) & (flips[:-1] == 0)) # HH
points_bob = np.sum(flips_diff == -1) # HT
if points_bob > points_alice:
bob_wins += 1
elif points_bob < points_alice:
alice_wins += 1
The catch is that Alice might score more points in a single game, but Bob wins more games. Let’s enumerate all possible outcomes with just 4 coin flips to understand why:
| Flips | Points Alice | Points Bob | Winner |
|---|---|---|---|
| TTTT | 0 | 0 | Draw |
| TTTH | 0 | 0 | Draw |
| TTHT | 0 | 1 | Bob |
| TTHH | 1 | 0 | Alice |
| THTT | 0 | 1 | Bob |
| THTH | 0 | 1 | Bob |
| THHT | 1 | 1 | Draw |
| THHH | 2 | 0 | Alice |
| HTTT | 0 | 1 | Bob |
| HTTH | 0 | 1 | Bob |
| HTHT | 0 | 2 | Bob |
| HTHH | 1 | 1 | Draw |
| HHTT | 1 | 1 | Draw |
| HHTH | 1 | 1 | Draw |
| HHHT | 2 | 1 | Alice |
| HHHH | 3 | 0 | Alice |
The breakdown shows Bob’s advantage: he wins more often than Alice in this simplified scenario. The total points across all games are equal (12 each), yet Bob wins more often by a small margin. Worth keeping in mind the next time a probability problem looks obvious.