Skip to content
Vamshi Jandhyala

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 00^\circ and 4545^\circ, the largest angular gaps between visible trees sit near the axis and near 4545^\circ (the tree at (1,1)(1,1)). The next-largest pair of adjacent gaps straddles which angle?

The Fiddler, Zach Wissner-Gross, April 25, 2025(original post)

Visible trees are the primitive lattice points. The widest interior gap pair flanks the ray to (2,1)(2,1).

Solution

A tree at (a,b)(a,b) is visible exactly when gcd(a,b)=1\gcd(a,b)=1, so the visible directions are the fractions b/ab/a, 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 0/10/1 and 1/11/1, the widest pair belongs to 1/21/2, whose neighbours are exactly those endpoints. So the angle is arctan1226.565.\arctan\tfrac12\approx\boxed{26.565^\circ}.

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 12,13,23,14,25,\tfrac12,\tfrac13,\tfrac23,\tfrac14,\tfrac25,\dots, so the fifth is 2/52/5: arctan2521.80.\arctan\tfrac25\approx\boxed{21.80^\circ}. (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