Skip to content

Instantly share code, notes, and snippets.

@sebastianhaas
Created December 3, 2019 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastianhaas/bfaaa29038d727a8f67ad2d2cb2fc8d2 to your computer and use it in GitHub Desktop.
Save sebastianhaas/bfaaa29038d727a8f67ad2d2cb2fc8d2 to your computer and use it in GitHub Desktop.
Advent of Code 2019 Day 1
import math
def calc_total_fuel(masses):
fuel_sum = 0
for x in masses:
fuel_sum += calc_fuel(x)
return fuel_sum
def calc_fuel(mass):
fuel = math.floor(mass / 3.0) - 2
if fuel > 0:
return fuel + calc_fuel(fuel)
else:
return 0
input_masses = []
with open('day1_input.txt') as inputs:
for line in inputs:
input_masses.append(int(line))
print(calc_total_fuel(input_masses))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment