mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 12:50:32 +01:00
More loops to numpy
This commit is contained in:
@@ -41,14 +41,11 @@ class DayRunner(SeparateRunner):
|
|||||||
per_signal = defaultdict(int)
|
per_signal = defaultdict(int)
|
||||||
|
|
||||||
for row_scores, row_deltas in zip(field, delta):
|
for row_scores, row_deltas in zip(field, delta):
|
||||||
seen = set()
|
unique, positions = numpy.unique(
|
||||||
|
sliding_window_view(row_deltas, 4), return_index=True, axis=0
|
||||||
|
)
|
||||||
|
|
||||||
for window, price in zip(
|
for key, index in zip(unique, positions):
|
||||||
sliding_window_view(row_deltas, 4), row_scores[4:]
|
per_signal[tuple(key)] += row_scores[index + 4]
|
||||||
):
|
|
||||||
key = tuple(window)
|
|
||||||
if key not in seen:
|
|
||||||
seen.add(key)
|
|
||||||
per_signal[key] += price
|
|
||||||
|
|
||||||
return max(per_signal.values())
|
return max(per_signal.values())
|
||||||
|
|||||||
Reference in New Issue
Block a user