edgekit

Classic brainteasers

Quant probability has a canon of brainteasers that has been stable for decades: the coupon collector, the hundred prisoners, the drunk passenger, the broken stick. The canon endures because each problem isolates a single powerful technique — linearity over stages, cycle structure, symmetry, an invariant, a geometric picture. This chapter solves the canon twice over: the thirty-second answer that nails the number, and the rigorous argument that survives “prove it.”

Intuition — classify before you compute

Almost every classic yields to one of five moves. (1) Linearity + indicators or stages: decompose the quantity into pieces whose expectations are easy (random variables & moments). (2) Symmetry: find an exchangeable structure that makes outcomes equally likely. (3) Recursion / first-step analysis: condition on the first move (Markov chains). (4) Invariant: find something the randomness cannot change. (5) Geometry: map uniform randomness to area or volume. Say which move you are making out loud — the classification is worth as much as the arithmetic.

The coupon collector#

Problem. Each trial produces one of equally likely coupon types, independently. How many trials until you have collected all types?

Fast answer. Break the collection into stages. While you hold distinct types, each trial is “new” with probability , so the stage length is geometric with mean . Linearity of expectation sums the stages — no independence between stages needed:

Worked number: for a die, rolls to see every face.

Rigorous — variance and concentration

The stage lengths are independent (each stage restarts the Bernoulli structure), so variances add. A geometric with success probability has variance , hence

so the standard deviation is of order — much smaller than the mean , which is why the collection time concentrates. For the tail, a union bound over coupons gives — the classic threshold. Compare the tail-bound machinery in inequalities & tail bounds.

Histogram of simulated coupon-collector completion times for n = 50 with the mean n H_n marked, showing right skew and concentration around n log n
Simulated coupon-collector times. The distribution sits near n ln n with standard deviation of order n — the mean n H_n (line) is a reliable summary, but the right tail is real: the last few coupons dominate the wait.

The 100 prisoners and the boxes#

Problem.100 prisoners’ names are placed in 100 boxes, one per box, uniformly at random. Each prisoner may open 50 boxes, looking for their own name; no communication after the search starts. All must succeed or all die. Random guessing gives success probability . Find a strategy with success probability over 30%.

Fast answer. The boxes define a permutation (box contains name ). Strategy: follow the cycle — prisoner opens box , then the box labelled by the name found, and so on. Prisoner is walking the cycle of containing and finds their name in exactly (cycle length) steps. Everyone succeeds iff the longest cycle has length . The failure probability is the chance of a cycle longer than 50, and cycles longer than are unique, so their probabilities add.

Rigorous — the probability a cycle of length k exists

Count permutations of elements containing a cycle of length : choose the cycle’s elements ways, arrange them in a cycle ways, permute the rest ways:

These events are disjoint (two cycles longer than cannot coexist), so with :

As the failure probability tends to , so the success probability tends to — it does not decay with . The strategy works by correlatingthe prisoners’ fates: they fail together or succeed together, converting a product of small probabilities into a single event about cycle structure.

Diagram of a permutation decomposed into cycles, with the follow-the-cycle strategy path highlighted and the success probability versus longest cycle length
The permutation's cycle decomposition decides everyone's fate at once. Following the cycle starting at your own box always finds your name in exactly cycle-length steps — so success is the single event {longest cycle <= 50}, which has probability about 31%.
prisoners_sim.py
import numpy as np

rng = np.random.default_rng(11)

def longest_cycle(perm):
    seen = np.zeros(perm.size, dtype=bool)
    best = 0
    for i in range(perm.size):
        length, j = 0, i
        while not seen[j]:
            seen[j] = True
            j = perm[j]
            length += 1
        best = max(best, length)
    return best

trials = 20_000
wins = sum(longest_cycle(rng.permutation(100)) <= 50 for _ in range(trials))
print(f"follow-the-cycle success: {wins / trials:.4f}")            # ~0.312
print(f"theory 1 - (H_100 - H_50): {1 - np.sum(1 / np.arange(51, 101)):.4f}")
print(f"random guessing:          {0.5 ** 100:.1e}")               # 7.9e-31

The drunk passenger (airplane seat)#

Problem. 100 passengers board a full plane in order. Passenger 1 has lost their boarding pass and sits in a uniformly random seat. Every later passenger takes their own seat if free, otherwise a uniformly random free seat. What is the probability passenger 100 gets their own seat?

Answer: — and it earns three proofs, in ascending rigor.

  • Symmetry. Every person who chooses randomly is choosing uniformly among free seats, and seats 1 and 100 are both free until one of them is taken (taking seat 1 ends all displacement; taking seat 100 dooms the last passenger). Each random chooser treats the two symmetrically, so seat 1 is taken before seat 100 with probability — and passenger 100 gets their seat exactly when seat 1 goes first.
  • Recursion. Let be the answer for passengers. Passenger 1 picks seat 1 (probability , success certain), seat (probability , failure certain), or seat with — in which case passengers 2 through sit normally and passenger becomes a new drunk passenger in a plane of seats. So ; with , induction gives for all .
  • Invariant. At every moment before the last boarding, at most one passenger is displaced, and the process ends the first time a random chooser picks seat 1 or seat 100. Whatever the history, the next random pick is uniform over a free set containing both terminal seats — so the stopped state is a fair coin no matter the path. This is a baby optional-stopping argument: the conditional probability of ending at “seat 1 first” is a martingale pinned at .
Rigorous — the variant: which passengers get displaced?

For passenger of , the relay of random choices made before boards ends the first time a chooser picks a seat in : seat 1 stops all displacement, seat displaces passenger , and any seat pauses the relay until after has boarded safely. Each random choice is uniform over free seats, so by symmetry every element of is equally likely to be hit first:

Sanity checks: gives (only if passenger 1 sat there directly), gives — the original answer falls out as a special case.

The broken stick#

Problem. Break a unit stick at two points chosen independently and uniformly. What is the probability the three pieces form a triangle?

Fast answer. A triangle forms iff no piece exceeds (triangle inequality). The three events “piece exceeds ” are disjoint and each has probability : the left piece is long iff both cuts land in the right half (), the right piece symmetrically, and the middle piece is long iff the cuts are more than apart — the two corner triangles of the unit square, total area . So .

Rigorous — the geometric region

Let the cuts be , uniform on the unit square. Condition on (probability , symmetric case identical). The pieces are , and all three are below iff

a triangle of area inside the half-square of area . Doubling over the two orderings gives total probability . Beware the classic bait-and-switch variant: break the stick, then break the longer piece — the sampling scheme changes and the answer becomes . Always ask how the randomness is generated.

The two envelopes#

Problem. Two envelopes hold and . You pick one, see amount , and reason: “the other holds or with probability each, so its expected value is — I should always swap.” And having swapped, the same logic says swap back. Where is the error?

Fast answer. Work in terms of the pair, not the observed amount: the two envelopes contain and , you hold each with probability , so both “keep” and “swap” have expected value . Swapping gains exactly zero by symmetry.

Rigorous — the conditioning error

The fallacy is the step . That conditional probability depends on the prior over : by Bayes, it equals where is the density of the smaller amount. For it to be at every you would need for all — a “uniform on all scales” prior, which integrates to infinity and is not a probability distribution. Under any proper prior, seeing carries information: large makes “you hold the bigger one” more likely, and the conditional expected gain from swapping integrates to exactly zero. The paradox is a disguised lesson in conditioning: expectations computed against an improper implicit prior are not expectations.

How many uniforms to exceed 1?#

Problem. Draw iid uniform on and let . Find .

Fast answer. Use the tail-sum formula (proved in random variables & moments) plus the simplex volume :

Rigorous — the simplex volume by induction

Claim: for . Base case . Inductive step, conditioning on the last draw:

Geometrically this is the volume of the corner simplex . Then and the tail sum telescopes into the series for . Bonus fact for the follow-up: the expected overshoot and the full distribution follow from differencing the tails.

Buffon’s needle#

Problem. Drop a needle of length on a floor ruled with parallel lines a distance apart. What is the probability the needle crosses a line?

Fast answer. Quote and verify the answer : for it is , and it scales linearly in — as it must, since for a short needle the expected number of crossings is additive over segments (linearity again: bend the needle into any shape of total length and the expected crossing count is unchanged — “Buffon’s noodle”).

Rigorous — integrate over position and angle

Let be the distance from the needle’s centre to the nearest line and its acute angle to the lines, independent. The needle crosses iff . Since ,

Dropping needles and counting crossings therefore estimates — the original Monte-Carlo method, two centuries early. The modern toolkit for such estimators (standard errors, variance reduction) is in simulation & Monte Carlo.

Three quick classics#

Three ants on a triangle. Each ant sits on a vertex and walks along a randomly chosen adjacent edge. Fast: no collision iff all three walk clockwise or all counterclockwise — . Rigorous: the 8 direction-choices are equally likely; any mixed choice puts two ants on one edge head-on or into the same vertex — enumerate to confirm exactly 2 of 8 outcomes are collision-free. On an -gon the same argument gives .

Tigers and sheep. 100 perfectly rational tigers and one sheep. A tiger that eats the sheep becomes a sheep itself (and can then be eaten); every tiger prefers eating to not eating, but survival above all. Does the sheep get eaten? Fast: parity. Rigorous: induct on the number of tigers . : the tiger eats — no threat remains. : eating would leave the eater as a sheep facing one tiger, who (by the base case) eats — so neither moves; the sheep is safe. In general the sheep is eaten iff is odd, since eating hands the next mover the position. With (even) the sheep survives. The technique — backward induction over a shrinking game — is the same first-step analysis you use for hitting-time problems.

Birthday collisions. With people and days, fast: pairs collide, and there are pairs each colliding with probability , so — about at . Rigorous: the exact probability is ; taking logs and using recovers the exponential form with error . The full derivation is in counting & combinatorics; what matters here is the square-root law: collisions appear once .

Quant lens — birthday collisions are why strategy zoos overfit

Replace people with strategy variants and days with effectively-independent ways a backtest can look good. Test variants and you are running implicit pairwise comparisons — coincidences (two variants sharing the same lucky trades, a variant matching the benchmark’s best year) arrive on the scale, quadratically faster than intuition expects. Meanwhile the best-looking of zero-edge strategies shows a Sharpe growing like (derived in multiple testing & paradoxes). A grid search over 100 parameter settings is not 100 chances to find an edge — it is 4,950 chances to find a coincidence. This is the probabilistic core of why backtests lie and of overfitting detection.

The canon at a glance#

ProblemAnswerKey move
Coupon collector (n types)n H_n ≈ n ln n + 0.577nGeometric stages + linearity
100 prisoners, 50 boxes≈ 31.2% (→ 1 − ln 2)Cycle structure; disjoint long-cycle events
Drunk passenger, last seat1/2Symmetry of seats 1 and n / invariant
Broken stick triangle1/4Geometry in the unit square
Uniforms to exceed 1eTail-sum + simplex volume 1/n!
Buffon's needle (L = d)2/π ≈ 0.637Integrate over position and angle
Three ants, no collision1/4 (n-gon: 2^{1−n})Enumerate; only unanimous directions work
Tigers and sheep (T = 100)Sheep survives (even T)Parity + backward induction

Speed round#

Problem 1 — Same semicircle

Three points are chosen uniformly at random on a circle. What is the probability all three lie in some semicircle?

Solution. For each point , let be the event that the semicircle starting at point and running clockwise contains the other two points. The are disjoint (only the clockwise-first point of a containing semicircle can start it), and each has probability . So the answer is . For points the same disjoint-union argument gives . The slick move — turning “some semicircle” into a disjoint union indexed by which point leads — is the insight worth articulating.

Problem 2 — First six wins

You and an opponent alternate rolling a fair die; you roll first. The first player to roll a 6 wins. What is your probability of winning?

Solution. Let be your winning probability. You win now with probability ; otherwise (probability ) your opponent becomes the first mover, winning with probability , so you win with : . Slicker: your winning rolls are attempts , giving the geometric series — but the fastest framing is that consecutive attempts’ win odds decay by a factor , so the odds are in your favour.

Problem 3 — Cards until the first ace

Cards are dealt one at a time from a well-shuffled 52-card deck. What is the expected number of cards dealt up to and including the first ace?

Solution. Symmetry: the 4 aces split the other 48 cards into 5 exchangeable gaps, so each gap has expected size . The first ace arrives after the first gap: . Rigorous version: each non-ace card precedes all four aces with probability (uniform relative order of 5 cards), so by indicators the expected number of non-aces before the first ace is — the same exchangeability argument that powers order statistics.

Problem 4 — Drunk passenger, passenger 60

In the 100-passenger drunk-passenger setup, what is the probability that passenger 60 gets their own seat?

Solution. By the relay argument above, passenger is displaced with probability : the relay of random choices ends at the first pick from the symmetric seats , and only seat hurts them. With : . Early passengers are nearly safe; the danger concentrates on the last few seats.

Next: from puzzles to inference — what it means to estimate a quantity from data, and how to judge one estimator against another. Estimators & sampling theory.