aoc/2022/day01.py

43 lines
679 B
Python

#!/usr/bin/env python3
from typing import TextIO
calories = []
def part1(puzzle: TextIO) -> int:
cur_cals = 0
for line in puzzle:
line = line.strip()
if line != "":
cur_cals += int(line)
else:
calories.append(cur_cals)
cur_cals = 0
calories.append(cur_cals) # last line
return max(calories)
def part2() -> int:
three_total = 0
i = 0
while i <= 3 - 1:
top = max(calories)
calories.remove(top)
three_total += top
i += 1
return three_total
if __name__ == "__main__":
puzzle = open("day01.txt")
print(part1(puzzle))
print(part2())