puzzle #3
In this lesson

Wide tables, equations, and code scroll sideways. Swipe, or Tab to focus them and use the left and right arrow keys.

Buffon’s needle

You will learn: Relate a geometric crossing experiment to its angle and length assumptions.

Start with: Uniform distribution · Events and probability

In 1777, Georges-Louis Leclerc, Comte de Buffon asked: if you drop a needle of length ℓ\ell onto a floor with parallel lines spaced dd apart (ℓ≤d\ell \leq d), what is the probability the needle crosses a line?

The answer connects a purely geometric experiment to π:

P(cross)=2ℓπdP(\text{cross}) = \frac{2\ell}{\pi d}

Rearranging, you get a Monte Carlo estimator for π:

π≈2ℓNd⋅C\pi \approx \frac{2\ell N}{d \cdot C}

Here needle centers are uniform relative to the parallel lines, orientations are uniform on [0,π), and drops are independent. N counts all drops and C counts crossings. The formula assumes ℓ ≤ d. With C=0 the ratio is undefined; the demo reports this explicitly.

Make a prediction

If you halve the needle length while keeping the line spacing fixed, what happens to the expected crossing count?

Explore the answer

It halves, since the crossing probability is proportional to needle length for ℓ≤d. Fewer crossings generally make the estimate of π less precise at the same number of drops.

π ≈ 3.07692 error: 0.06467
325 crossings / 500 needles
Value by

How uncertain is this estimate?

Nominal 95% interval for π: [2.896, 3.294]. This transforms a Wilson interval for the crossing probability by reversing its endpoints. It is an approximate repeated-sampling procedure; π itself is fixed.

π estimate and interval by independent repeat02468102030405060independent repeatπ estimate and interval

57 of 60 intervals include π; 0 repeats have no crossings and an undefined point estimate. Each repeat uses 500 independent drops. Solid intervals include π; dashed intervals miss it. The plot stops at 8: 0 intervals extend above the display, including unbounded ones.

Read the exact results for all 60 repeats
RepeatCrossingsEstimate95% intervalIncludes π
13093.2363.032 to 3.480Yes
23093.2363.032 to 3.480Yes
33233.0962.913 to 3.316Yes
43163.1652.971 to 3.396Yes
53103.2263.024 to 3.468Yes
63283.0492.872 to 3.261Yes
73213.1152.929 to 3.339Yes
83033.3003.087 to 3.555Yes
93273.0582.880 to 3.272Yes
103193.1352.946 to 3.362Yes
113033.3003.087 to 3.555Yes
123173.1552.963 to 3.385Yes
133253.0772.896 to 3.294Yes
143233.0962.913 to 3.316Yes
153313.0212.849 to 3.229Yes
163103.2263.024 to 3.468Yes
173442.9072.751 to 3.096No
183153.1752.980 to 3.408Yes
193303.0302.856 to 3.239Yes
203113.2153.015 to 3.456Yes
213223.1062.921 to 3.327Yes
223133.1952.997 to 3.432Yes
233223.1062.921 to 3.327Yes
243123.2053.006 to 3.444Yes
253193.1352.946 to 3.362Yes
263123.2053.006 to 3.444Yes
273203.1252.937 to 3.350Yes
283153.1752.980 to 3.408Yes
293213.1152.929 to 3.339Yes
303223.1062.921 to 3.327Yes
313083.2473.041 to 3.493Yes
323113.2153.015 to 3.456Yes
332963.3783.153 to 3.647No
343223.1062.921 to 3.327Yes
353173.1552.963 to 3.385Yes
363033.3003.087 to 3.555Yes
373103.2263.024 to 3.468Yes
383333.0032.833 to 3.208Yes
393043.2893.078 to 3.543Yes
403183.1452.954 to 3.373Yes
413213.1152.929 to 3.339Yes
423183.1452.954 to 3.373Yes
433193.1352.946 to 3.362Yes
443233.0962.913 to 3.316Yes
453133.1952.997 to 3.432Yes
463213.1152.929 to 3.339Yes
473432.9152.758 to 3.105No
483123.2053.006 to 3.444Yes
493323.0122.841 to 3.218Yes
503273.0582.880 to 3.272Yes
513223.1062.921 to 3.327Yes
523113.2153.015 to 3.456Yes
533352.9852.818 to 3.187Yes
543183.1452.954 to 3.373Yes
553123.2053.006 to 3.444Yes
563323.0122.841 to 3.218Yes
573143.1852.988 to 3.420Yes
583093.2363.032 to 3.480Yes
593153.1752.980 to 3.408Yes
603083.2473.041 to 3.493Yes
Solid needles cross a line; dashed needles do not. P(cross) = 2L/π = 63.66% for spacing 1 and L ≤ 1. The estimate is 2LN/crossings; it is undefined with zero crossings. Showing last 250 of 500.

What to notice

  • The estimate converges slowly. After 500 needles the estimate might still be off by 0.02–0.1. Monte Carlo estimators for π converge at rate 1/N1/\sqrt{N} — you need 100× more needles to gain one decimal place.
  • Solid crosses, dashed misses. A needle crosses a line when its centre is within (ℓ/2)∣sin⁡θ∣(\ell/2)|\sin\theta| of the nearest line, where θ is the needle’s angle.
  • Resample to see a new realisation and how much the estimate varies from run to run.

Why π appears

The crossing probability comes from integrating over all possible needle positions and angles. The integral of sin⁡θ\sin\theta over [0,π][0, \pi] evaluates to 2, and dividing by the normalising constant π\pi is what injects π into the formula. The geometry forces trigonometry, and trigonometry carries π.

From geometry to probability

Let U be the distance from the center to the nearest line. Uniform placement makes U uniform on [0,d/2]. At angle θ, crossing requires U≤(ℓ/2)|sin θ|. Since ℓ≤d, this gives conditional probability (ℓ/d)|sin θ|. Averaging over uniform θ in [0,π) gives:

P(cross)=1π∫0πℓdsin⁡θ dθ=2ℓπdP(\text{cross})=\frac{1}{\pi}\int_0^\pi\frac{\ell}{d}\sin\theta\,d\theta=\frac{2\ell}{\pi d}

Longer needles can cross multiple lines, and the conditional probability above can exceed one before being capped. That is why this experiment restricts ℓ/d to at most one; substituting longer lengths into the short-needle formula is invalid.

An interval, not extra decimal places

Each independent drop contributes a Bernoulli crossing indicator, so C has a binomial distribution. The demo constructs a nominal 95% Wilson interval [p_low,p_high] for its success probability and transforms it to [2ℓ/(d·p_high), 2ℓ/(d·p_low)]. The endpoint order reverses because the reciprocal decreases.

When C=0, the point estimate is undefined and the upper interval endpoint is unbounded. Those runs remain in the repeated-experiment display and coverage denominator. The finite plot clips large interval endpoints only for drawing; the table preserves their values.

Wilson coverage is approximate and varies with sample size and crossing probability. The fraction of 60 displayed intervals containing π is itself noisy; it need not be 95%. Increasing N reduces typical sampling error at an asymptotic 1/√N rate, but cannot guarantee that the next estimate improves. The reciprocal estimator also has finite-sample bias.

Make a prediction

Does an interval containing 3.14159 mean this run established five accurate decimal places?

Explore the answer

No. Read the whole interval width. Displayed digits are formatting, while repeated sampling reveals how much estimates fluctuate. Quadrupling N roughly halves typical error, rather than adding a fixed number of correct digits.

Reference

NIST: confidence intervals for a binomial proportion describes Wilson score inversion and distinguishes approximate intervals from exact binomial procedures. The reciprocal transformation above applies it to this experiment.

Reset all settings