day 01
the tyranny of the rocket equation
approach
the input is a list of module masses. part 1 maps each one to mass // 3 - 2 and sums the results.
part 2 has to account for the fuel needing fuel of its own. total_fuel keeps applying the same formula to the last amount and adds each step to a running total, stopping as soon as the result drops to zero or below.
the trick
an assignment expression in the while condition computes the next amount and tests it in one go.
python
def total_fuel(f):
s=0
while (f:=(f//3)-2)>0:
s+=f
return s