Skip to content

Commit

Permalink
More loops to numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
bertptrs committed Dec 22, 2024
1 parent 230b4ae commit 321d78d
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions 2024/src/aoc/days/day22.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ def part2(cls, input: str) -> int:
per_signal = defaultdict(int)

for row_scores, row_deltas in zip(field, delta):
seen = set()

for window, price in zip(
sliding_window_view(row_deltas, 4), row_scores[4:]
):
key = tuple(window)
if key not in seen:
seen.add(key)
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]

return max(per_signal.values())

0 comments on commit 321d78d

Please sign in to comment.