lets go bois

This commit is contained in:
cupcakearmy 2022-12-01 14:08:24 +01:00
parent e3fe7fb6bc
commit d57a850d01
2 changed files with 52 additions and 0 deletions

11
2022/01/README.md Normal file
View File

@ -0,0 +1,11 @@
# 01
Another year, here we go again!
<details>
<summary>Solutions</summary>
<ol>
<li>68292</li>
<li>203203</li>
</ol>
</details>

41
2022/01/python/main.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
from os.path import dirname, join
# Day 01
# Common
def read_input(filename):
data = join(dirname(__file__), '..', filename)
with open(data) as f:
return f.read().strip()
test = read_input('test.txt')
data = read_input('input.txt')
def count_calories(data: str, top_three=False) -> int:
calories = [
sum([int(calories) for calories in elve.split('\n')])
for elve in data.split('\n\n')
]
calories = sorted(calories, reverse=True)
if not top_three:
return calories[0]
else:
return sum(calories[0:3])
# 1
print('1.')
print(count_calories(test))
print(count_calories(data))
# 2
print('\n2.')
print('1.')
print(count_calories(test, True))
print(count_calories(data, True))