repl.it
@21natzil/

Day 1

Python

Fuel calculations challenge

fork
loading
Files
  • main.py
  • input.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
with open('input.txt') as f:
  masses = [*map(int, f.readlines())]

fuel_partial = sum(map(lambda x: x // 3 - 2, masses))
print("Partial Fuel:", fuel_partial)

def recursive_fuel(starting: int, start = True):
  additional_fuel = starting // 3 - 2
  if additional_fuel <= 0:
    return starting if not start else 0
  else:
    return (starting if not start else 0) + recursive_fuel(additional_fuel, False)

print("Total Fuel", sum(map(recursive_fuel, masses)))