def required_fuel(mass: int) -> int:
return mass // 3 - 2
for mass in [12, 14, 1969, 100756]:
print(f"{mass}: {required_fuel(mass)}")
input = []
with open("AoC/input1.txt") as input_file:
input = [int(x) for x in input_file.readlines()]
sum(required_fuel(x) for x in input)
def total_required_fuel(mass: int) -> int:
fuel = required_fuel(mass)
total_fuel = fuel
while fuel > 0: # I would love to use the walrus operator here
fuel = required_fuel(fuel)
if fuel > 0:
total_fuel += fuel
return total_fuel
for mass in [14, 1969, 100756]:
print(f"{mass}: {total_required_fuel(mass)}")
sum(total_required_fuel(x) for x in input)
limit = 300
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')
plt.figure(figsize=(15, 8))
plt.scatter(x=list(range(limit)), y=[required_fuel(x) for x in range(limit)], s=3, label="Fuel for mass")
plt.scatter(x=list(range(limit)), y=[total_required_fuel(x) for x in range(limit)], s=3, label="Total fuel")
plt.xlabel("Mass (some units)")
plt.ylabel("Fuel (some other units)")
plt.legend()
plt.show()