2019-12-01 - The Tyranny of the Rocket Equation
(original .ipynb)
Day 1 puzzle input is a list of integers which represent weight of some modules on a spacecraft (mine is here). Part 1 involves applying a calculation to the weight to determine how much fuel is required, and summing up all fuel requirements Part 2 is an adjusted version of this calculation to take on board the fact that fuel adds weight that needs to be carried.
from math import floor def required_fuel(mass): return (floor(mass/3.0)) - 2 assert 2 == required_fuel(12) assert 2 == required_fuel(14) assert 654 == required_fuel(1969) assert 33583 == required_fuel(100756)
module_weights_lines = open("puzzle_input/day1.txt", "r").readlines() module_weights = [int(mw) for mw in module_weights_lines] module_fuel_required = [ required_fuel(module) for module in module_weights ] print(sum(module_fuel_required))
3305301
def fully_loaded_fuel(module): total_fuel_required = required_fuel(module) additional_fuel = required_fuel(total_fuel_required) while additional_fuel > 0: total_fuel_required += additional_fuel additional_fuel = required_fuel(additional_fuel) return total_fuel_required assert 2 == fully_loaded_fuel(14) assert 966 == fully_loaded_fuel(1969) assert 50346 == fully_loaded_fuel(100756) fully_loaded_module_fuel_required = [ fully_loaded_fuel(module) for module in module_weights ] print(sum(fully_loaded_module_fuel_required))
4955106