Solve 2024:1 p1-2 "Historian Hysteria"
Realized afterwards I got the ints() helper, so original code before cleanup splitted the input and mapped all words with int(). valuable seconds lost there. Also, collections.Counter() was used initially since I was too tired to remember count() method in lists. Line 8 took the longest time to figure out. A typo took 1-3 minutes to find for part 2. Form: Sleep deprived, felt slow.
This commit is contained in:
parent
cb50d62e3f
commit
81741232af
1 changed files with 20 additions and 0 deletions
20
2024-python/output/day_01.py
Normal file
20
2024-python/output/day_01.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from output import ints
|
||||
|
||||
|
||||
def solve(puzzle_input):
|
||||
left, right = [sorted(col) for col in zip(*map(ints, puzzle_input.splitlines()))]
|
||||
|
||||
p1 = sum(abs(l - r) for l, r in zip(left, right))
|
||||
p2 = sum(k * right.count(k) for k in left)
|
||||
|
||||
return p1, p2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("./input/01.txt", "r") as f:
|
||||
puzzle_input = f.read().strip()
|
||||
|
||||
p1, p2 = solve(puzzle_input)
|
||||
|
||||
print(p1)
|
||||
print(p2)
|
||||
Loading…
Add table
Reference in a new issue