Books · The Fiddler: Solutions
Chapter 57
Can You See Between the Trees?
From the origin you look out at a forest with a (thin) tree at every point with nonnegative integer coordinates; a tree hides any tree directly behind it. Between and , the largest angular gaps between visible trees sit near the axis and near (the tree at ). The next-largest pair of adjacent gaps straddles which angle?
The Fiddler, Zach Wissner-Gross, April 25, 2025(original post)
Solution
A tree at is visible exactly when , so the visible directions are the fractions , organised by the Stern–Brocot (Farey) tree. A fraction’s two flanking gaps are widest when it is born early, with simple neighbours. After the endpoints and , the widest pair belongs to , whose neighbours are exactly those endpoints. So the angle is
The computation
Generate the visible directions as they are born in the Stern–Brocot tree: each new fraction is the mediant of the two it is inserted between, and those two are its birth neighbours. Record the smaller of its two flanking gaps and rank.
from math import atan, degrees
best = []
def rec(lp, lq, rp, rq, d): # Stern-Brocot mediant + its birth neighbours
if d > 12: return
mp, mq = lp + rp, lq + rq
aM, aL, aR = degrees(atan(mp/mq)), degrees(atan(lp/lq)), degrees(atan(rp/rq))
best.append((min(aM - aL, aR - aM), (mp, mq), aM))
rec(lp, lq, mp, mq, d + 1); rec(mp, mq, rp, rq, d + 1)
rec(0, 1, 1, 1, 0)
best.sort(reverse=True)
print(best[0][1], round(best[0][2], 3)) # (1, 2) 26.565
Extra Credit
The fifth-largest pair of adjacent gaps in this range straddles which angle?
Solution
Ranking the Stern–Brocot fractions by the smaller of their two birth gaps gives the order , so the fifth is : (The source’s value is paywalled; this is my own, under the natural birth-gap ranking.)
The computation
The same ranked list from the main section, read down to the fifth entry.
for i in range(5): print(best[i][1], round(best[i][2], 3)) # ... 5th: (2, 5) 21.801