advent_of_code/2022/1/1_2.py
2022-12-03 02:57:25 +01:00

21 lines
460 B
Python

#!/usr/bin/env python
# 2022 - Advent Of Code 1 - part 2
# file = 'input_example.txt'
file = 'input2.txt'
calories = []
with open(file, encoding="utf-8") as f:
accum = 0
for line in f.readlines():
if line == '\n':
# next elf
calories.append(accum)
accum = 0
else:
accum += int(line)
calories.append(accum)
calories.sort(reverse=True)
print(calories[0:3])
print(sum(calories[0:3]))