adventofcode/2022/01/day1.py
2022-12-02 09:41:56 +01:00

27 lines
502 B
Python

def load(filename: str) -> list[int]:
elves = []
with open(filename) as f:
calories = 0
for l in f:
cals = l.strip()
if cals == "":
elves.append(calories)
calories = 0
continue
calories += int(cals)
elves.append(calories)
return elves
demo = sorted(load("demo.txt"), reverse=True)
data = sorted(load("data.txt"), reverse=True)
# Part 1
assert max(demo) == 24000
print("Part 1: ", max(data))
# Part 2
assert sum(demo[0:3]) == 45000
print("Part 2: ", sum(data[0:3]))