-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1.py
35 lines (27 loc) · 802 Bytes
/
day1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
data = open("input.txt", "r").read().strip().split("\n")
def part_one(data: list[str]):
max_calories = 0
current_calories = 0
for line in data:
if line == "":
current_calories = 0
else:
calories = int(line)
current_calories += calories
max_calories = max(max_calories, current_calories)
return max_calories
def part_two(data: list[str]):
elfs = []
current_calories = 0
for line in data:
if line == "":
elfs.append(current_calories)
current_calories = 0
else:
calories = int(line)
current_calories += calories
elfs.sort(reverse=True)
return sum(elfs[0:3])
if __name__ == "__main__":
print(part_one(data))
print(part_two(data))