From 29e33f8f6a31565f5a2671b1c459ff1b829630f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 8 Dec 2019 11:06:56 +0100 Subject: Refactor and create main.py --- solutions/py/d01.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 solutions/py/d01.py (limited to 'solutions/py/d01.py') diff --git a/solutions/py/d01.py b/solutions/py/d01.py new file mode 100644 index 0000000..d5197ab --- /dev/null +++ b/solutions/py/d01.py @@ -0,0 +1,19 @@ +import math +import sys + +def get_fuel(mass): + fuel = math.floor(mass / 3) - 2 + return 0 if fuel <= 0 else fuel + get_fuel(fuel) + +def pt1(_in): + s = 0 + for line in _in: + mass = int(line) + if mass == 0: + break + fuel = math.floor(mass / 3) - 2 + s += fuel + return s + +def pt2(input): + return sum([get_fuel(int(line)) for line in input]) -- cgit v1.2.1