Chapter 88
When Will The Fall Colors Peak?
Riddler Express
A solar year is about days. The Gregorian calendar uses leap years per , giving . Find and (with ) so that leap years every years makes the average day-count as close as possible to .
Solution
We want the leap fraction as close as possible to the fractional part , since the average year length is . Scanning every denominator below and choosing the best numerator , the closest is giving , off the target by under of a day, a good deal sharper than the Gregorian .
The computation
For each pick the minimising and keep the best pair.
best = (1, None, None)
for n in range(1, 400):
l = round(0.24217 * n)
err = abs(0.24217 * n - l)
if err < best[0]: best = (err, n, l)
print(best[1], best[2]) # 351 85
Riddler Classic
Each tree starts changing colour at a uniformly random time between the equinox and the solstice, then drops its leaves at a uniformly random later time before the solstice. Across all trees, what is the largest fraction simultaneously in mid-change?
Solution
Scale the season to . A tree starts at and ends at , and it is mid-change at time when . The fraction of trees changing at is exactly . Conditioning on the start , the end exceeds with probability , so Maximise over : with , this is , whose derivative vanishes at . The peak fraction is therefore The colours peak when a fraction of the season has passed, with just over a third of the trees changing at once.
The computation
Evaluate the changing-fraction across the season and take its maximum; a direct tree-by-tree simulation lands on the same value.
import numpy as np
t = np.linspace(1e-9, 1 - 1e-9, 1_000_000)
print((-(1 - t) * np.log(1 - t)).max(), 1 / np.e) # 0.3679, 0.3679