advent-of-code/2022/day1.py

21 lines
433 B
Python
Raw Normal View History

2022-12-01 18:10:40 +00:00
# -*- encoding: utf-8 -*-
2022-12-03 10:42:09 +00:00
import sys
2022-12-01 18:10:40 +00:00
2022-12-03 10:42:09 +00:00
lines = sys.stdin.readlines()
2022-12-01 18:10:40 +00:00
2022-12-02 08:21:38 +00:00
# we store the list of calories for each elf in values, and we use the last element
# of values to accumulate
2022-12-01 18:10:40 +00:00
values: list[int] = [0]
for line in lines:
if not line.strip():
values = values + [0]
else:
values[-1] += int(line.strip())
# part 1
2022-12-06 14:28:46 +00:00
print(f"answer 1 is {max(values)}")
2022-12-01 18:10:40 +00:00
# part 2
2022-12-06 14:28:46 +00:00
print(f"answer 2 is {sum(sorted(values)[-3:])}")