Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day13(s, *, part2=False):
- num_diff = 1 if part2 else 0
- total = 0
- for section in s.split('\n\n'):
- grid = np.array([list(line) for line in section.splitlines()])
- reflections = []
- for axis in range(2):
- for i in range(1, len(grid)):
- h = min(i, len(grid) - i) # Shortest height.
- if np.sum(grid[i - h : i] != grid[i : i + h][::-1]) == num_diff:
- reflections.append((axis, i))
- grid = grid.T
- ((axis, i),) = reflections
- total += i * [100, 1][axis]
- return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement