28 lines
502 B
Python
28 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]))
|