2022 - Day 1 part 2
This commit is contained in:
parent
940d738c4f
commit
7cd33c640e
2 changed files with 2276 additions and 0 deletions
21
2022/1/1_2.py
Normal file
21
2022/1/1_2.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/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]))
|
2255
2022/1/input2.txt
Normal file
2255
2022/1/input2.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue