-
Notifications
You must be signed in to change notification settings - Fork 0
/
day01.py
48 lines (35 loc) · 1.07 KB
/
day01.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
36
37
38
39
40
41
42
43
44
45
46
47
48
def day_01_part_1():
# how many calories top elf carries in total?
file = open("01input") # 01example returns correct 24k calories
contents = file.readlines()
sums = [0] # initial value for accessing 0 index
elf_index = 0
largest_number = 0
for x in contents:
if x != "\n":
sums[elf_index] += int(x)
else:
sums.append(0)
elf_index += 1
for x in sums:
if x > largest_number:
largest_number = x
return largest_number
def day_01_part_2():
# how many calories top 3 elves carry in total?
file = open("01input") # 01example returns correct 24k calories
contents = file.readlines()
sums = [0] # initial value for accessing 0 index
elf_index = 0
largest_number = 0
for x in contents:
if x != "\n":
sums[elf_index] += int(x)
else:
sums.append(0)
elf_index += 1
sums.sort(reverse=True)
total = sums[0] + sums[1] + sums[2]
return total
if __name__ == '__main__':
print(day_01_part_2())