We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 230b4ae commit 321d78dCopy full SHA for 321d78d
2024/src/aoc/days/day22.py
@@ -41,14 +41,11 @@ def part2(cls, input: str) -> int:
41
per_signal = defaultdict(int)
42
43
for row_scores, row_deltas in zip(field, delta):
44
- seen = set()
45
-
46
- for window, price in zip(
47
- sliding_window_view(row_deltas, 4), row_scores[4:]
48
- ):
49
- key = tuple(window)
50
- if key not in seen:
51
- seen.add(key)
52
- per_signal[key] += price
+ unique, positions = numpy.unique(
+ sliding_window_view(row_deltas, 4), return_index=True, axis=0
+ )
+
+ for key, index in zip(unique, positions):
+ per_signal[tuple(key)] += row_scores[index + 4]
53
54
return max(per_signal.values())
0 commit comments