Chapter 250
How Fast Can You Skip To Your Favorite Song?
Riddler Express
On the planet Jakku (radius miles), the droid BB-8 must reach Rey, whose location is uniformly random on the surface. BB-8 rolls at miles per hour. Even knowing where Rey is, what is the probability BB-8 could reach her within hours?
The Riddler, FiveThirtyEight, December 6, 2019(original post)
Solution
In hours BB-8 can travel miles, so it can reach any point within miles of its start. Rey is reachable exactly when she lies in that small cap of the surface. The probability is the cap’s area divided by the whole surface. Over such a tiny radius the surface is essentially flat, so the cap is a disk of radius miles, area , against the sphere’s area : about one chance in . Accounting for the sphere’s curvature changes this only in the sixth decimal place (to ): the reachable patch is minuscule, which is why finding Rey is so hard.
The computation
Encode the area ratio, both with the flat-disk approximation and with the exact spherical cap (area for angular radius ), to show they agree to four significant figures.
import math
R, reach = 4000, 72
flat = math.pi * reach**2 / (4 * math.pi * R**2)
theta = reach / R # angular radius (radians)
cap = 2 * math.pi * R**2 * (1 - math.cos(theta)) / (4 * math.pi * R**2)
print(f"flat {100 * flat:.4f}%")
print(f"curved {100 * cap:.7f}%")
# flat 0.0081%
# curved 0.0080998%
Riddler Classic
A playlist has tracks to . “Next” moves to the next track (wrapping ); “Random” jumps to a uniformly random track (possibly the current one). Starting on a random track, you want to reach track in as few presses as possible. What is the best strategy, and the average number of presses?
The Riddler, FiveThirtyEight, December 6, 2019(original post)
Solution
“Next” is great when you are just short of ; “Random” is the escape hatch when you are far away. So the strategy is a threshold: press “Next” if you are within tracks before , otherwise press “Random” and try again. The only question is the cutoff .
Suppose you use cutoff and let be the average number of presses from a random start. With probability your start is already within of (the tracks ), needing on average Next-presses. Otherwise you press Random once and are back to a random track, expecting more presses. So Minimising over whole gives and
The balance is intuitive: Next alone wastes presses crawling across the whole list, Random alone keeps overshooting, and the hybrid spends a Random press only until it lands in the short home stretch.
The computation
Encode it two ways: the threshold formula minimised over , and an independent value iteration on the -track Markov decision process (each state’s value is one press plus the cheaper of Next and the Random average). They should agree.
# threshold formula
k, B = min(((k, k/2 + (99 - k)/(k + 1)) for k in range(100)), key=lambda t: t[1])
print(f"formula: k={k}, B={B:.3f}")
# value iteration on the full MDP (Random may restart the current track)
V = [0.0] * 101
for _ in range(100000):
rand = sum(V[1:101]) / 100 # value of pressing Random
new = [0.0 if s == 42 else 1 + min(V[s % 100 + 1], rand) for s in range(101)]
if max(abs(a - b) for a, b in zip(new[1:], V[1:])) < 1e-12: V = new; break
V = new
print(f"MDP: average presses = {sum(V[1:101]) / 100:.3f}")
# formula: k=13, B=12.643
# MDP: average presses = 12.643
Both give a cutoff of and about presses on average.