Implement 2019 day 1 with tests in Python

This commit is contained in:
2021-01-23 15:52:12 +01:00
parent 69de955158
commit 07db73aa3e
8 changed files with 223 additions and 0 deletions

23
2019/aoc2019/day01.py Normal file
View File

@@ -0,0 +1,23 @@
from typing import TextIO
def fuel_required(weight: int) -> int:
return max(0, weight // 3 - 2)
def recursive_fuel_required(weight: int) -> int:
total = 0
while weight > 0:
weight = fuel_required(weight)
total += weight
return total
def part1(data: TextIO) -> int:
return sum(fuel_required(int(line)) for line in data)
def part2(data: TextIO) -> int:
return sum(recursive_fuel_required(int(line)) for line in data)