Chapter 163
Three Daughters And One Hundred Boxes
Riddler Express
A farmer wants to divide his square farm into three pieces of equal area using fencing. What is the shortest total length of fence he needs?
The Riddler, FiveThirtyEight, October 6, 2017(original post)
Solution
The obvious answer, two parallel cuts of length , uses miles of fence. A T-shape with one full cut and a short perpendicular spur uses . A Y-shape with two straight diagonals does slightly better, around . But the optimum is none of these: it uses three circular arcs meeting at a Steiner point at to one another, and totals about miles.
Why arcs, and why . The classical Steiner condition for shortest networks says that three boundary curves meeting at a free interior point must do so at equal angles. Otherwise the local geometry permits a perturbation that strictly shortens the network. The same condition forces each curve to meet the square’s boundary at a right angle (or else a tangential slide along the boundary would shorten the curve). The third condition is that each curve has constant curvature, that is, each is a circular arc (or a line segment, the zero-curvature special case): along an arc of varying curvature one could swap a short piece for one of constant curvature with the same endpoints and strictly less length under the area constraint.
These three conditions, taken together with the demand that the three regions have area each, pin down a one-parameter family of candidate networks. The symmetric solution, with the Steiner point on the vertical axis of symmetry and two mirror-image arcs running to the two side edges plus a straight stem to the bottom edge, is the global optimum (the asymmetric variants are dominated).
Setting it up. Place the unit square with corners at , , , . By symmetry put the Steiner point for some , drop a straight stem from to the midpoint of the bottom edge, and have one arc leave at above horizontal and end perpendicular to the right edge at , with the mirror arc going left.
Pinning down the arc. The tangent at points in direction . The centre of the arc is perpendicular to the tangent on the concave side, at the constant distance equal to the radius . For the arc to also meet the right edge perpendicular to that edge, the centre must lie on the right edge itself. These two requirements fix The arc sweeps from at central angle to its endpoint at , so its arc length is . Two arcs and a stem give total length .
Pinning down the stem. The area constraint demands each region equals . Take the right-bottom region (bounded counter-clockwise by the bottom edge from to , the right edge from to , the right arc back to , and the stem down to ). Applying the shoelace formula and integrating along the arc gives, with , Setting and solving for numerically gives . Adding the two arc lengths, The straight-Y configuration is only about a thousandth of a mile longer than this; the curvature wins by a thin margin but is the true optimum.
The computation
Encode the geometry: compute the area of the right-bottom region as a function of the stem length , then root-find for . Sum the resulting stem plus two arcs of length .
Define the arc’s centre and endpoint from the geometry above.
Compute the right-bottom area by Green’s theorem along the closed boundary.
Root-find for .
Report .
import numpy as np
from scipy.optimize import brentq
def area_right_bot(z):
y_E = z + 1 - np.sqrt(3) / 2
cy = z - np.sqrt(3) / 2
a, b = np.pi / 2, 2 * np.pi / 3
arc = ((b - a)
+ (np.sin(b) - np.sin(a))
+ cy * (np.cos(a) - np.cos(b)))
return 0.5 * (y_E + arc - 0.5 * z)
z = brentq(lambda z: area_right_bot(z) - 1 / 3, 0.3, 0.8)
print(round(z, 4)) # 0.5761
print(round(z + np.pi / 3, 4)) # 1.6233
Riddler Classic
You and three friends are on a game show. Four boxes hold your four names, one per box. Each player enters the room alone, opens up to two boxes, and looks for their own name. Everyone enters exactly once. You win if all four find their own name. Find a strategy that beats the naive . Extra credit: players, boxes, openings each.
The Riddler, FiveThirtyEight, October 6, 2017(original post)
Solution
The trick is to give each player a linked search, in which finding her name on any player’s tour is automatic, by following the permutation’s cycles. The strategy and its analysis are due to Anna Gál and Peter Bro Miltersen.
The strategy. Number the players and the boxes . Player first opens box . If she finds her own name she is done. If she finds the name of player , she next opens box , then (whichever name was in box ), and so on, up to her opening limit of two.
The contents of the boxes define a permutation on : box contains the name of player . Decompose into disjoint cycles. Player ’s tour walks the cycle containing : she sees , and finds her own name on the step that closes the cycle. So she wins iff her cycle has length at most (the opening limit).
Every player wins iff every cycle has length at most . Out of the permutations on four letters, the ones with no cycle longer than are those whose cycle type is , , or . There is of the first type (the identity), of the second (one transposition, two fixed points), and of the third (two disjoint transpositions). Total . Comfortably more than .
Extra credit. With players, boxes, and openings each, the same cycle strategy applies. The team wins iff the random permutation on has no cycle of length greater than . At most one such long cycle can exist, since two cycles of length more than would need more than elements between them.
For each , count the permutations with a cycle of length exactly . Choose which of the elements form that cycle ( ways), arrange them into a cycle ( ways for a directed cycle on vertices), and permute the remaining elements freely ( ways). The total is so the fraction of permutations with such a cycle is . These events are disjoint for different (only one long cycle can exist), so where is the -th harmonic number. As with the opening limit fixed at , the win probability tends to , a constant independent of the number of prisoners. This is the celebrated -prisoners theorem.
The computation
For , enumerate all permutations and count those whose longest cycle is at most . For , simulate random permutations and check the same condition. Both should reproduce the boxed values.
For : iterate over all permutations of ; for each, compute its cycle structure; count those with maximum cycle length .
For : generate random permutations, find the longest cycle of each, count those with length .
from itertools import permutations
import random
def max_cycle_len(p):
seen = [False] * len(p)
best = 0
for i in range(len(p)):
if seen[i]: continue
j, L = i, 0
while not seen[j]:
seen[j] = True
j = p[j]
L += 1
if L > best: best = L
return best
n4 = sum(1 for p in permutations(range(4)) if max_cycle_len(p) <= 2)
print(n4, round(n4 / 24, 4)) # 10 0.4167
rng = random.Random(0)
N = 200_000
wins = 0
for _ in range(N):
p = list(range(100)); rng.shuffle(p)
if max_cycle_len(p) <= 50: wins += 1
print(round(wins / N, 4)) # ~0.3118
The four-box exhaustive count gives exactly; the -box Monte Carlo lands within sampling error of , matching both the boxed answer and the limit.