Skip to content

Commit 5efb40b

Browse files
committed
2024 d22: Whoops, fix bad operation order
1 parent 12ec873 commit 5efb40b

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

2024/solutions/day22.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ def map_sequence(n):
1515
n = ((n << 11) ^ n) & 0xffffff
1616

1717
value = n % 10
18-
19-
if i >= 3:
20-
# Use key as a compact hash of the last 4 diff values, using 5 bits
21-
# per value ([-9, 9] -> [1, 19]) with 0 meaning "no value".
22-
key = ((key & 0x7fff) << 5) | (value - prev + 10)
23-
if key not in diff_map:
24-
diff_map[key] = value
25-
18+
# Use key as a compact hash of the last 4 diff values, using 5 bits
19+
# per value ([-9, 9] -> [1, 19]) with 0 meaning "no value".
20+
key = ((key & 0x7fff) << 5) | (value - prev + 10)
2621
prev = value
2722

23+
if i >= 3 and key not in diff_map:
24+
diff_map[key] = value
25+
2826
return n, diff_map
2927

3028

0 commit comments

Comments
 (0)