Skip to content
Vamshi Jandhyala

Books · The Fiddler: Solutions

Chapter 40

How Far Can You Run Before Sundown?

A trail run ends at sundown, 7:007{:}00 p.m. There are four loops, of 11, 33, 3.53.5, and 4.54.5 miles, and after finishing each loop you are randomly (uniformly) assigned the next one. Only completed loops count. It is 5:555{:}55 p.m., you have just finished a loop, and you run a steady 1010-minute mile. On average, how many miles will you complete in the 6565 minutes before sundown?

The Fiddler, Zach Wissner-Gross, August 22, 2025(original post)

Solution

The four loops take 1010, 3030, 3535, and 4545 minutes. With TT minutes left you are handed a uniformly random loop; if it fits you run it and continue, otherwise the day ends. So the expected remaining score satisfies E(T)=14(mi,t){mi+E(Tt),tT,0,t>T,E(T)=\frac14\sum_{(\text{mi},\,t)} \begin{cases}\text{mi}+E(T-t), & t\le T,\\[2pt] 0,& t>T,\end{cases} over the four loops. Evaluating from T=65T=65 gives the exact E(65)=1993340964.866 miles.E(65)=\frac{19933}{4096}\approx\boxed{4.866\text{ miles}}.

The computation

Encode the assignment process: from TT minutes left, average over the four equally likely loops, running each (and recursing) only if it fits before sundown. Exact fractions, memoised on the time remaining.

from fractions import Fraction as F
from functools import lru_cache
loops = [(F(1), 10), (F(3), 30), (F(7, 2), 35), (F(9, 2), 45)]   # (miles, minutes)
@lru_cache(None)
def E(T):
    return sum((mi + E(T - t)) if t <= T else F(0) for mi, t in loops) / 4
print(E(65), round(float(E(65)), 5))                   # 19933/4096  4.86646

Extra Credit

Once during the race, if you dislike the loop you have just been assigned, you may take a mulligan: discard it and draw a fresh assignment (you must then keep the redraw). Using the mulligan optimally, what score can you expect?

Solution

Add a state for whether the mulligan is still available; for each draw you take the better of running it now or rerolling with the mulligan spent. This yields E=2192140965.352 miles.E=\frac{21921}{4096}\approx\boxed{5.352\text{ miles}}. (The source value is paywalled; this exact figure is my own.)

The computation

The same recursion with a mulligan flag: on each assignment, compare running it now against rerolling once (mulligan spent) and take the larger.

@lru_cache(None)
def Em(T, m):                                          # m = mulligans left
    tot = F(0)
    for mi, t in loops:
        run = (mi + Em(T - t, m)) if t <= T else F(0)
        tot += max(run, Em(T, m - 1)) if m > 0 else run     # reroll option
    return tot / 4
print(Em(65, 1), round(float(Em(65, 1)), 5))           # 21921/4096  5.35181