aoc/2022/day01.py

48 lines
783 B
Python

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