Advertisement
hhoppe

Advent of code 2023 day 21 obscure

Dec 22nd, 2023
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def day21_part2(s):
  2.   empty = np.tile(np.array([list(line) for line in s.splitlines()]) != '#', (5, 5))
  3.   a = np.zeros((657, 657), bool)
  4.   a[328, 328] = 1
  5.   for _ in range(327):
  6.     a[1:-1, 1:-1] = empty & (a[:-2, 1:-1] | a[2:, 1:-1] | a[1:-1, :-2] | a[1:-1, 2:])
  7.  
  8.   counts = a[1:-1, 1:-1].reshape(5, 131, 5, 131).sum((1, 3)).flat
  9.   return (
  10.       counts[12] * 40924885401
  11.       + counts[7] * 40925290000
  12.       + counts[[1, 3, 21, 23]].sum() * 202300
  13.       + counts[[6, 8, 16, 18]].sum() * 202299
  14.       + counts[[2, 10, 14, 22]].sum()
  15.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement