Chapter 117
Outrun the Angry Ram
You are tucked into the southeast corner of a square, fenced paddock. Two gates are equidistant from you, one at the southwest corner and one at the northeast corner. An angry ram charges in through the southwest gate and runs directly at you at constant speed, always pointing straight at wherever you are now. You run at constant speed north along the eastern fence toward the northeast gate. How much faster than you must the ram run so that it catches you exactly as you reach the gate?
The Riddler, FiveThirtyEight(original post)
Solution
A pursuit curve looks forbidding, but one bookkeeping trick avoids solving it. Track two running totals over the chase, the distance between ram and farmer, and how far north the ram has climbed, and tie them together through the single angle along which the ram is always looking.
Fix the farmer’s speed at and the side of the square at . Put the southwest gate (where the ram starts) at the origin, the farmer’s southeast corner at , and the northeast gate at . The farmer runs north up the line at speed , so he reaches the gate at time . Let the ram’s speed be . “Caught exactly at the gate” means that at the ram is also at , so the gap between them has just closed to zero.
Let be the angle between the ram’s heading, which always points straight at the farmer, and due north. Two facts follow from that single angle.
How the gap changes. Call the distance between ram and farmer . The ram slides along the line of sight toward the farmer at speed , which shrinks . The farmer, running north at speed , moves away along that same line of sight at the rate , which grows . So Integrating from to , and using that the gap starts at (southwest corner to southeast corner) and ends at ,
How far north the ram climbs. The ram moves at speed along a heading from north, so its northward speed is , and its total climb is But the ram climbs from the southwest gate at height to the northeast gate at height , a net rise of exactly . Setting the two expressions for that rise equal, The ram needs to be at least the golden ratio times your speed to run you down at the gate.
The computation
Re-run the chase and search for the speed that turns escape into capture. Step the farmer north at unit speed, step the ram straight toward him at speed , and record whether the ram reaches him before (capture) or not (escape). Binary-search across that boundary.
Place the farmer at and the ram at ; advance in tiny time steps.
Each step, move the ram a distance along the unit vector toward the farmer.
Capture if the gap closes before ; escape otherwise.
Bisect between an escaping and a capturing value.
import math
def escapes(V, dt=1e-5):
rx, ry, t = 0.0, 0.0, 0.0
while t < 1.0:
dx, dy = 1.0 - rx, t - ry # farmer at (1, t)
d = math.hypot(dx, dy)
if d < 1.5 * V * dt: # ram reaches farmer
return False
rx += V * dt * dx / d
ry += V * dt * dy / d
t += dt
return True # farmer reached the gate first
lo, hi = 1.0, 3.0
for _ in range(40):
mid = (lo + hi) / 2
lo, hi = (mid, hi) if escapes(mid) else (lo, mid)
print("critical V :", round((lo + hi) / 2, 5))
print("golden phi :", round((1 + 5 ** 0.5) / 2, 5))
# critical V : 1.61801
# golden phi : 1.61803