Buffon's needle

Press a button to drop needles on a lined floor. Each needle lands in a random place at a random angle. A needle that crosses a line turns orange. Now work out 2 × drops ÷ crossings. Drop 100 and look at the answer. Then guess what 10,000 will give before you press it.

Drop
line on the floorneedle crossing a lineneedle between lines

The estimate after each drop. The dashed line is π. The drop count is on a scale where each step is ten times more.

What's going on

Start with the needle as long as the gap between the lines. Then the chance that a needle crosses a line is exactly 2/π, about 0.637. So crossings ÷ drops is close to 2/π, and turning that around, 2 × drops ÷ crossings is close to π.

Why 2/π? Tilt a needle of length L at an angle θ to the lines. Measured straight across the lines, it reaches a distance L sin θ. The lines are d apart, so the chance it covers one is L sin θ ÷ d. Every angle from 0° to 180° is equally likely, and the average of sin θ over that range is 2/π. So the chance of a crossing is 2L/(πd). The π comes from averaging over a half turn.

Move the slider to make the needle shorter. The chance drops in proportion, so the estimate becomes 2 × (needle ÷ gap) × drops ÷ crossings. The slider stops at 1 because a longer needle can cross two lines at once and the rule changes.

The estimate is slow to settle. The error shrinks roughly like 1 over the square root of the number of drops, so one more correct digit costs about 100 times more needles. Sweep the floor and drop 10,000 a few times. You will get a different answer each time, and with the full-length needle most of them will be within 0.05 of π.

Sheet: Dropping needles to find π. A cousin of this demo: measure π with random darts.