Chapter 231
How Inefficient Can You Make Your Walk To Class?
Riddler Express
The following number pairs refer to coincidences in American history, from to the present: What pair belongs in the second position?
The Riddler, FiveThirtyEight, June 14, 2019(original post)
Solution
Read the numbers as the orders in which presidents served, and the coincidence is a shared surname. The nd and th presidents were John Adams and John Quincy Adams; the th and rd were the Harrisons (William Henry and Benjamin); the th and th were the Johnsons (Andrew and Lyndon); the th and nd were the Roosevelts (Theodore and Franklin). Each pair is two presidents who share a last name.
The list is in alphabetical order of that surname: Adams, then the missing one, then Harrison, Johnson, Roosevelt. The surname falling between Adams and Harrison is Bush, and the two Bushes were the st and rd presidents (George H. W. and George W.).
The computation
Encode the actual data and let the pattern fall out: list every president with their order number and surname, find the surnames carried by exactly two different presidents, and sort those pairs alphabetically by surname. The result must be the given sequence with in second place. One subtlety: Grover Cleveland was both the nd and th president (non-consecutive terms), but that is one man, not a shared-surname pair, so he is excluded.
from collections import defaultdict
pres = {1:"Washington",2:"Adams",3:"Jefferson",4:"Madison",5:"Monroe",
6:"Adams",7:"Jackson",8:"Van Buren",9:"Harrison",10:"Tyler",11:"Polk",
12:"Taylor",13:"Fillmore",14:"Pierce",15:"Buchanan",16:"Lincoln",
17:"Johnson",18:"Grant",19:"Hayes",20:"Garfield",21:"Arthur",
22:"Cleveland",23:"Harrison",24:"Cleveland",25:"McKinley",26:"Roosevelt",
27:"Taft",28:"Wilson",29:"Harding",30:"Coolidge",31:"Hoover",
32:"Roosevelt",33:"Truman",34:"Eisenhower",35:"Kennedy",36:"Johnson",
37:"Nixon",38:"Ford",39:"Carter",40:"Reagan",41:"Bush",42:"Clinton",
43:"Bush",44:"Obama",45:"Trump"}
by = defaultdict(list)
for n, s in pres.items():
by[s].append(n)
# surnames held by two DIFFERENT presidents (Cleveland is one man twice -> skip)
pairs = sorted((s, tuple(sorted(v))) for s, v in by.items()
if len(v) == 2 and s != "Cleveland")
for s, p in pairs:
print(f"{s:10s} {p}")
print("sequence:", [p for s, p in pairs])
# Adams (2, 6) / Bush (41, 43) / Harrison (9, 23) / Johnson (17, 36) / Roosevelt (26, 32)
# sequence: [(2, 6), (41, 43), (9, 23), (17, 36), (26, 32)]
The second entry is , the Bushes.
Riddler Classic
You cross a square courtyard, feet by feet, entering at the centre of the west wall and leaving at the centre of the south wall. You dislike sharp turns, so every turn has a radius of at least feet, and you never cross your own path. What is the longest walk you could take? Extra credit: can you make your walk a chosen length, say exactly feet?
The Riddler, FiveThirtyEight, June 14, 2019(original post)
Solution
The surprise is that there is no longest walk. As long as your path is an idealised curve of zero width, you can make it as long as you like.
The constraints are mild. Staying inside the courtyard bounds the region. The turn-radius rule says the path’s radius of curvature is at least feet everywhere, so it cannot wiggle too tightly. The no-crossing rule forbids self-intersection. None of these caps the length, because you can spiral. A spiral coils round and round without ever crossing itself, and you can wind it as many times as you please by making successive coils closer and closer together. The gap between neighbouring coils can shrink toward zero while each coil’s radius of curvature stays comfortably above feet, so an arbitrary number of turns fits inside the courtyard.
For the extra credit, length varies continuously as you add coils, from the short near-direct crossing up to as long as you like, so by the intermediate value theorem every target length above the minimum is attainable, feet included. You simply wind the spiral until its length is feet.
The computation
Encode the constraints on an explicit family of spirals and watch the length diverge. Use an Archimedean spiral centred in the courtyard, with . Its radius of curvature is , which for small pitch is close to , so keeping keeps . Hold the outer radius at feet (inside the -foot half-width) and shrink the pitch : the number of coils and the total length grow without bound while every constraint holds.
For a pitch , let run from to ; the coil count is .
Integrate arc length and track the minimum of .
Shrink and watch length diverge with and throughout.
import numpy as np
def spiral_stats(a, R, b): # Archimedean spiral r = a + b*theta
turns = (R - a) / (2 * np.pi * b)
t = np.linspace(0, 2 * np.pi * turns, int(80 * turns) + 2)
r = a + b * t
length = np.trapezoid(np.sqrt(r ** 2 + b ** 2), t)
rho = (r ** 2 + b ** 2) ** 1.5 / (r ** 2 + 2 * b ** 2)
return turns, length, rho.min(), r.max()
for b in (1.0, 0.5, 0.2, 0.1, 0.05, 0.02):
turns, L, rmin, rmax = spiral_stats(6.0, 22.0, b)
print(f"b={b:5}: turns={turns:6.1f} length={L:9.1f} "
f"min_rho={rmin:4.2f} r_max={rmax:4.1f}")
from scipy.optimize import brentq # extra credit: hit 350 ft exactly
b350 = brentq(lambda b: spiral_stats(6.0, 22.0, b)[1] - 350.0, 0.3, 1.0)
turns, L, rmin, rmax = spiral_stats(6.0, 22.0, b350)
print(f"EC: b={b350:.4f} -> length {L:.1f} ft, min_rho {rmin:.2f}, r_max {rmax:.1f}")
# length grows without bound as b shrinks, with min_rho >= 5 and r_max = 22 (inside court)
# EC: b=0.6408 -> length 350.0 ft, min_rho 5.97, r_max 22.0
As the pitch shrinks, the length climbs through hundreds, thousands, and beyond, while the minimum radius of curvature stays above feet and the spiral never leaves the courtyard or crosses itself. The walk is unbounded, and tuning the pitch lands any chosen length, such as feet.