(update) 2022 day 01
This commit is contained in:
14
2022/01/example
Normal file
14
2022/01/example
Normal file
@ -0,0 +1,14 @@
|
||||
1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000
|
||||
2235
2022/01/input
Normal file
2235
2022/01/input
Normal file
File diff suppressed because it is too large
Load Diff
21
2022/01/main.py
Normal file
21
2022/01/main.py
Normal file
@ -0,0 +1,21 @@
|
||||
with open("input") as file:
|
||||
cal: list = []
|
||||
elf = 1
|
||||
|
||||
calories = 0
|
||||
for line in file.readlines():
|
||||
|
||||
if line.strip() == "":
|
||||
|
||||
cal.append((elf, calories))
|
||||
|
||||
elf += 1
|
||||
calories = 0
|
||||
continue
|
||||
|
||||
calories += int(line.strip())
|
||||
|
||||
cal.sort(key=lambda x: -x[1])
|
||||
|
||||
print("part1:", cal[0])
|
||||
print("part2:", sum(list(map(lambda x: x[1], cal[:3]))))
|
||||
Reference in New Issue
Block a user