Chapter 46
Breaking A Slide Rule Into Four Pieces
A foot-long ruler is accidentally sliced at three random points, making four pieces of different lengths. On average, how long is the piece that contains the 6-inch mark?
The Riddler, FiveThirtyEight(original post)
Solution
The piece holding the -inch mark runs from the nearest cut below it to the nearest cut above it (or to a ruler end if there is no cut on that side). So its length is the distance up to the first cut above the mark plus the distance down to the first cut below, and we can find each by itself.
Let the ruler have length and the mark sit at , a fraction of the way along, with cuts placed uniformly. A given cut lands within distance above the mark with probability , so the chance that none of the cuts falls in that strip is . Integrating this survival probability, the expected distance from the mark up to the first cut above it is and likewise the distance down to the first cut below has expectation . Adding them, With , and , The marked piece averages well over the -inch length of a typical quarter, because the piece straddling a fixed point tends to be one of the longer ones.
The computation
Slice the ruler at three random points and measure the piece spanning the -inch mark, averaged over many rulers.
import numpy as np
rng = np.random.default_rng(0)
runs = 2_000_000; total = 0.0
for _ in range(runs):
cuts = np.sort(rng.uniform(0, 12, 3))
ends = np.concatenate(([0.0], cuts, [12.0]))
for lo, hi in zip(ends[:-1], ends[1:]):
if lo < 6 < hi:
total += hi - lo; break
print(total / runs) # ~5.625