Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 163

Three Daughters And One Hundred Boxes

Riddler Express

A farmer wants to divide his 1×11 \times 1 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 11, uses 22 miles of fence. A T-shape with one full cut and a short perpendicular spur uses 1+231.671 + \tfrac23 \approx 1.67. A Y-shape with two straight diagonals does slightly better, around 1.6351.635. But the optimum is none of these: it uses three circular arcs meeting at a Steiner point at 120120^{\circ} to one another, and totals about 1.62331.6233 miles.

Why arcs, and why 120120^{\circ}. The classical Steiner condition for shortest networks says that three boundary curves meeting at a free interior point must do so at equal 120120^{\circ} 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 13\tfrac13 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 (0,0)(0, 0), (1,0)(1, 0), (1,1)(1, 1), (0,1)(0, 1). By symmetry put the Steiner point S=(12,z)S = (\tfrac12, z) for some z>0z > 0, drop a straight stem from SS to the midpoint of the bottom edge, and have one arc leave SS at 3030^{\circ} above horizontal and end perpendicular to the right edge at (1,yE)(1, y_E), with the mirror arc going left.

Pinning down the arc. The tangent at SS points in direction (cos30,sin30)=(32,12)(\cos 30^{\circ}, \sin 30^{\circ}) = (\tfrac{\sqrt{3}}{2}, \tfrac12). The centre of the arc is perpendicular to the tangent on the concave side, at the constant distance equal to the radius RR. 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 R=1,C=(1,  z32),yE=z+132.R = 1, \quad C = (1,\; z - \tfrac{\sqrt{3}}{2}), \quad y_E = z + 1 - \tfrac{\sqrt{3}}{2}. The arc sweeps from SS at central angle 2π3\tfrac{2\pi}{3} to its endpoint at π2\tfrac{\pi}{2}, so its arc length is R(2π3π2)=π6R \cdot (\tfrac{2\pi}{3} - \tfrac{\pi}{2}) = \tfrac{\pi}{6}. Two arcs and a stem give total length z+π3z + \tfrac{\pi}{3}.

Pinning down the stem. The area constraint demands each region equals 13\tfrac13. Take the right-bottom region (bounded counter-clockwise by the bottom edge from (12,0)(\tfrac12, 0) to (1,0)(1, 0), the right edge from (1,0)(1, 0) to (1,yE)(1, y_E), the right arc back to SS, and the stem down to (12,0)(\tfrac12, 0)). Applying the shoelace formula and integrating along the arc gives, with C=(1,  z32)C = (1,\; z - \tfrac{\sqrt{3}}{2}), 2A=yEz2+π/22π/3 ⁣ ⁣[1+cosϕ+(z32)sinϕ]dϕ=yEz2+π6+(sin2π31)(z32)(cos2π30).\begin{aligned} 2A &= y_E - \tfrac{z}{2} + \int_{\pi/2}^{2\pi/3}\!\!\big[1 + \cos\phi + (z - \tfrac{\sqrt{3}}{2})\sin\phi\big]\,d\phi\\ &= y_E - \tfrac{z}{2} + \tfrac{\pi}{6} + (\sin\tfrac{2\pi}{3} - 1) - (z - \tfrac{\sqrt{3}}{2})(\cos\tfrac{2\pi}{3} - 0). \end{aligned} Setting A=13A = \tfrac13 and solving for zz numerically gives z0.5761z \approx 0.5761. Adding the two arc lengths, L=z+π30.5761+1.04721.6233 miles.L = z + \tfrac{\pi}{3} \approx 0.5761 + 1.0472 \approx \boxed{1.6233 \text{ miles.}} 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 zz, then root-find for A(z)=13A(z) = \tfrac13. Sum the resulting stem plus two arcs of length π6\tfrac{\pi}{6}.

  1. Define the arc’s centre C(z)C(z) and endpoint yE(z)y_E(z) from the geometry above.

  2. Compute the right-bottom area A(z)A(z) by Green’s theorem along the closed boundary.

  3. Root-find for A(z)=13A(z) = \tfrac13.

  4. Report L=z+π3L = z + \tfrac{\pi}{3}.

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 1/161/16. Extra credit: 100100 players, 100100 boxes, 5050 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 1,2,3,41, 2, 3, 4 and the boxes 1,2,3,41, 2, 3, 4. Player ii first opens box ii. If she finds her own name she is done. If she finds the name of player jj, she next opens box jj, then kk (whichever name was in box jj), and so on, up to her opening limit of two.

The contents of the boxes define a permutation σ\sigma on {1,2,3,4}\{1, 2, 3, 4\}: box ii contains the name of player σ(i)\sigma(i). Decompose σ\sigma into disjoint cycles. Player ii’s tour walks the cycle containing ii: she sees σ(i),σ2(i),σ3(i),\sigma(i), \sigma^2(i), \sigma^3(i), \ldots, and finds her own name on the step that closes the cycle. So she wins iff her cycle has length at most 22 (the opening limit).

Every player wins iff every cycle has length at most 22. Out of the 4!=244! = 24 permutations on four letters, the ones with no cycle longer than 22 are those whose cycle type is (1,1,1,1)(1, 1, 1, 1), (2,1,1)(2, 1, 1), or (2,2)(2, 2). There is 11 of the first type (the identity), (42)=6\binom{4}{2} = 6 of the second (one transposition, two fixed points), and 12(42)=3\tfrac{1}{2}\binom{4}{2} = 3 of the third (two disjoint transpositions). Total 1010. Pr(team wins)=102441.7%.\boxed{\,\Pr(\text{team wins}) = \tfrac{10}{24} \approx 41.7\%.\,} Comfortably more than 1/166.25%1/16 \approx 6.25\%.

Extra credit. With 100100 players, 100100 boxes, and 5050 openings each, the same cycle strategy applies. The team wins iff the random permutation σ\sigma on {1,,100}\{1, \ldots, 100\} has no cycle of length greater than 5050. At most one such long cycle can exist, since two cycles of length more than 5050 would need more than 100100 elements between them.

For each k>50k > 50, count the permutations with a cycle of length exactly kk. Choose which kk of the 100100 elements form that cycle ((100k)\binom{100}{k} ways), arrange them into a cycle ((k1)!(k-1)! ways for a directed cycle on kk vertices), and permute the remaining 100k100 - k elements freely ((100k)!(100 - k)! ways). The total is (100k)(k1)!(100k)!=100!k,\binom{100}{k}(k - 1)!\,(100 - k)! = \frac{100!}{k}, so the fraction of permutations with such a cycle is 1/k1/k. These events are disjoint for different k>50k > 50 (only one long cycle can exist), so Pr(some cycle has length>50)=k=511001k=H100H50,\Pr(\text{some cycle has length} > 50) = \sum_{k=51}^{100} \frac{1}{k} = H_{100} - H_{50}, where Hn=1+12++1nH_n = 1 + \tfrac12 + \cdots + \tfrac1n is the nn-th harmonic number. Pr(team wins)=1(H100H50)10.6882=0.3118.\Pr(\text{team wins}) = 1 - (H_{100} - H_{50}) \approx 1 - 0.6882 = 0.3118. Pr(team wins with 100 boxes)31.18%.\boxed{\,\Pr(\text{team wins with } 100 \text{ boxes}) \approx 31.18\%.\,} As nn \to \infty with the opening limit fixed at n/2n/2, the win probability tends to 1ln20.30691 - \ln 2 \approx 0.3069, a constant independent of the number of prisoners. This is the celebrated 100100-prisoners theorem.

The computation

For n=4n = 4, enumerate all 2424 permutations and count those whose longest cycle is at most 22. For n=100n = 100, simulate random permutations and check the same condition. Both should reproduce the boxed values.

  1. For n=4n = 4: iterate over all permutations of {1,2,3,4}\{1, 2, 3, 4\}; for each, compute its cycle structure; count those with maximum cycle length 2\leq 2.

  2. For n=100n = 100: generate random permutations, find the longest cycle of each, count those with length 50\leq 50.

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 10/2410/24 exactly; the 100100-box Monte Carlo lands within sampling error of 0.31180.3118, matching both the boxed answer and the 1ln21 - \ln 2 limit.