Add 2022 day 1
This commit is contained in:
parent
f4d8aef702
commit
c08fea2ade
3 changed files with 2308 additions and 0 deletions
2267
2022/day_1/data.txt
Normal file
2267
2022/day_1/data.txt
Normal file
File diff suppressed because it is too large
Load diff
27
2022/day_1/day1.py
Normal file
27
2022/day_1/day1.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
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]))
|
14
2022/day_1/demo.txt
Normal file
14
2022/day_1/demo.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000
|
Loading…
Reference in a new issue