Skip to content

Commit

Permalink
Add solution to 2024-12-22
Browse files Browse the repository at this point in the history
  • Loading branch information
fuglede committed Dec 22, 2024
1 parent 51f1abf commit 90e7bdb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 2024/day22/solutions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from collections import defaultdict
import numpy as np

with open("input") as f:
ns = list(map(int, f.read().strip().split("\n")))


def hsh(secret):
for _ in range(2000):
secret ^= secret << 6 & 0xFFFFFF
secret ^= secret >> 5 & 0xFFFFFF
secret ^= secret << 11 & 0xFFFFFF
yield secret


secrets = list(map(list, map(hsh, ns)))

# Part 1
print(sum(s[-1] for s in secrets))

# Part 2
result = defaultdict(int)
for n in ns:
ss = [s % 10 for s in hsh(n)]
diffs = np.diff(ss)
changes = set()
for i in range(1996):
if (change := tuple(diffs[i : i + 4])) not in changes:
changes.add(change)
result[change] += ss[i + 4]

print(max(result.values()))

0 comments on commit 90e7bdb

Please sign in to comment.