Add 2022 solutions

This commit is contained in:
2024-07-07 20:34:52 -04:00
parent d582dfc777
commit e9ba9cee63
28 changed files with 2774 additions and 30 deletions

20
2022/d1.py Normal file
View File

@@ -0,0 +1,20 @@
from lib import *
def solve(input: Input, second=False):
ps = input.text.split("\n\n")
xss = map(lambda p: map(int, p.splitlines()), ps)
xs = list(map(sum, xss))
if not second:
return max(xs)
xs.sort()
return sum(xs[-3:])
def main():
DAY_INPUT = "d1.txt"
print("Solution 1:", solve(Input(DAY_INPUT)))
assert solve(Input(DAY_INPUT)) == 69883
print("Solution 2:", solve(Input(DAY_INPUT), True))
assert solve(Input(DAY_INPUT), True) == 207576
if __name__ == "__main__":
main()