Solve 2022 day 1 pt 1-2
This commit is contained in:
parent
7b5c9c393b
commit
e791b19ab2
1 changed files with 26 additions and 0 deletions
26
2022-python/output/day_01.py
Normal file
26
2022-python/output/day_01.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
from output import ints
|
||||||
|
|
||||||
|
|
||||||
|
def solve(data):
|
||||||
|
E = data.split("\n\n")
|
||||||
|
p1 = 0
|
||||||
|
C = []
|
||||||
|
for e in E:
|
||||||
|
e = sum(ints(e))
|
||||||
|
p1 = max(p1, e)
|
||||||
|
C.append(e)
|
||||||
|
p2 = sum(sorted(C, reverse=True)[:3])
|
||||||
|
return p1, p2
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
with open("./input/01.txt", "r") as f:
|
||||||
|
inp = f.read().strip()
|
||||||
|
|
||||||
|
p1, p2 = solve(inp)
|
||||||
|
|
||||||
|
print(p1)
|
||||||
|
print(p2)
|
||||||
|
|
||||||
|
assert p1 == 66616
|
||||||
|
assert p2 == 199172
|
||||||
Loading…
Add table
Reference in a new issue