advent-of-code/2019/01/day1.py

14 lines
322 B
Python
Raw Permalink Normal View History

2019-12-01 19:37:24 +01:00
import sys
from typing import List
def cost(mass: int) -> int:
return mass // 3 - 2
def cost_rec(mass: int) -> int:
c = cost(mass)
return 0 if c <= 0 else c + cost_rec(c)
lines = [int(l) for l in sys.stdin.readlines()]
print(f'Part 1: {sum(map(cost, lines))}')
print(f'Part 2: {sum(map(cost_rec, lines))}')