Advertisement
hhoppe

Advent of code 2024 day 8

Dec 8th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. def day8(s, *, part2=False):
  2.   grid = np.array([list(line) for line in s.splitlines()])
  3.   antinodes = np.full(grid.shape, 0)
  4.   for symbol in set(np.unique_values(grid)) - {'.'}:
  5.     for pair in itertools.permutations(np.argwhere(grid == symbol), 2):
  6.       for t in itertools.count(1) if part2 else [2]:
  7.         y, x = (1 - t) * pair[0] + t * pair[1]
  8.         if not (0 <= y < grid.shape[0] and 0 <= x < grid.shape[1]):
  9.           break
  10.         antinodes[y, x] = 1
  11.   return antinodes.sum()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement