OLIVER SCOTT
Home / Probability notebook

Probability notebook

Twelve classic interview problems. Each is solved on paper first, then checked by a 400,000-trial simulation in Python. Press a button to re-run any simulation live in your browser.

Waiting for a six

How many rolls of a fair die do you expect before the first six?

Geometric with p = 1/6, so the mean is 1/p.

Answer6exact 6.00 Python sim 6.01

HH versus HT

Flip a fair coin until you see HH. What's the expected number of flips? And for HT?

First-step analysis: E[HH] = 6 because a miss after H sends you back to the start; E[HT] = 4 because after H you only wait for a T. Same probability per pair, different waiting times.

Answer6 (and 4)exact 6.000 Python sim 5.998 · HT 4.0026 (exact 4)

Collecting every face

How many rolls until you've seen all six faces?

Coupon collector: sum of geometric waits 6/6 + 6/5 + … + 6/1 = 6·H₆.

Answer6·H₆ ≈ 14.70exact 14.70 Python sim 14.68

Birthday problem

With 23 people, what's the chance two share a birthday?

1 − ∏(365 − k)/365 for k = 0…22.

Answer≈ 0.5073exact 0.5073 Python sim 0.5077

Broken stick

Break a stick at two uniform random points. What's the chance the three pieces form a triangle?

A triangle needs every piece under 1/2; the valid region is 1/4 of the unit square.

Answer1/4exact 0.2500 Python sim 0.2501

Gambler's ruin

Start with $10, bet $1 at a time with win probability 0.49. What's the chance of reaching $20 before $0?

With r = q/p: (1 − r10)/(1 − r20). A tiny edge against you compounds.

Answer≈ 0.4013exact 0.4013 Python sim 0.3983

Monty Hall

You pick one of three doors; the host opens a losing door. Should you switch?

Switching wins exactly when your first pick was wrong, which happens 2/3 of the time.

Answerswitch: 2/3exact 0.6667 Python sim 0.6662

Max of two dice

What's the expected maximum of two fair dice?

P(max ≤ k) = (k/6)², so P(max = k) = (2k − 1)/36 and the mean is 161/36.

Answer161/36 ≈ 4.472exact 4.4722 Python sim 4.4713

Centre in the triangle

Pick three random points on a circle. What's the chance their triangle contains the centre?

The centre is inside unless all three fall in one semicircle, which has probability 3/4.

Answer1/4exact 0.2500 Python sim 0.2493

Optional reroll

Roll a die and win its face value. You may reroll once and must keep the second roll. What's the optimal expected value?

Reroll when the first roll is below 3.5, the value of a fresh roll: ½·3.5 + ½·5 = 4.25.

Answer4.25exact 4.2500 Python sim 4.2506

Secret Santa

52 people draw names at random. What's the chance nobody draws their own?

Inclusion–exclusion: Σ(−1)ᵏ/k! → 1/e. The expected number of fixed points is exactly 1 for any n.

Answer≈ 1/e ≈ 0.3679exact 0.3679 Python sim 0.3646

Uniforms past one

Add uniform(0,1) numbers until the sum exceeds 1. How many do you expect to need?

P(N > n) = P(sum of n uniforms < 1) = 1/n!, so E[N] = Σ 1/n! = e.

Answere ≈ 2.718exact 2.7183 Python sim 2.7180

Simulations differ from the exact answers by sampling error only: the standard error at 400,000 trials is about 0.001 for probabilities.