Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day8(s, *, part2=False):
- grid = np.array([list(line) for line in s.splitlines()])
- antinodes = np.full(grid.shape, 0)
- for symbol in set(np.unique_values(grid)) - {'.'}:
- for pair in itertools.permutations(np.argwhere(grid == symbol), 2):
- for t in itertools.count(1) if part2 else [2]:
- y, x = (1 - t) * pair[0] + t * pair[1]
- if not (0 <= y < grid.shape[0] and 0 <= x < grid.shape[1]):
- break
- antinodes[y, x] = 1
- return antinodes.sum()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement