Advertisement
hhoppe

Advent of code 2024 day 10 part 2 fast numpy

Dec 10th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. def day10_part2(s):
  2.   grid = np.array([list(line) for line in s.splitlines()], int)
  3.   grid = np.pad(grid, 1, constant_values=-1)
  4.   a = np.zeros(grid.shape, int)
  5.   a[grid == 0] = 1
  6.  
  7.   for i in range(1, 10):
  8.     a[1:-1, 1:-1] = a[:-2, 1:-1] + a[2:, 1:-1] + a[1:-1, :-2] + a[1:-1, 2:]
  9.     a[grid != i] = 0
  10.  
  11.   return a.sum()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement