day 14
reindeer olympics
approach
each reindeer is a (speed, fly time, rest time) tuple. the distance after any number of seconds has a closed form: full cycles with divmod, plus whatever part of the last cycle is spent flying.
part 1 is the largest distance at the final second. part 2 evaluates that same formula at every second, finds the reindeer tied for the lead and gives each a point, then returns the best score.
the trick
distance at time t is a formula, so nobody has to be simulated second by second.
python
def kms(seconds, fs, fd, rd):
d, m = divmod(seconds, fd + rd)
return (d * fd * fs) + (min(m, fd) * fs)