Buffon's Needle

Drop a needle of length L randomly onto a floor of parallel lines spaced d apart. The probability that the needle crosses a line is 2L / (πd) — provably so by Buffon in 1733. Run the simulation and count crossings: the ratio 2L · drops / (d · crossings) approaches π out of thin air.

The floor — drop needles, watch crossings
drops
0
crossings
0
Estimate of π converges
π estimate
—
|π − est|
—
L / d (needle ratio) 0.80
drops / sec 50
why π appears (without circles)
A needle of length L lands at angle θ ∈ [0, π) and centre at distance y ∈ [0, d/2) from the nearest line. The needle crosses a line iff y ≤ (L/2)·sin θ. The probability is the area of {(y, θ) : y ≤ (L/2)·sin θ} divided by the rectangle's area:

P = (1/(πd/2)) · ∫₀^π (L/2)·sin θ dθ = (2/(πd)) · L

That π appears because we integrated sin θ over a half-cycle — and the half-cycle has length π by definition. Solving for π: π ≈ (2L · drops) / (d · crossings). Mario Lazzarini (1901) claimed to estimate π to six decimals from 3408 needles. Probably cheated. Without cheating, you'd need about 4 million drops to nail 4 digits — the convergence rate is 1/√N.