Advertisement
hhoppe

Advent of code 2023 day 13

Dec 13th, 2023 (edited)
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. def day13(s, *, part2=False):
  2.   num_diff = 1 if part2 else 0
  3.   total = 0
  4.  
  5.   for section in s.split('\n\n'):
  6.     grid = np.array([list(line) for line in section.splitlines()])
  7.  
  8.     reflections = []
  9.     for axis in range(2):
  10.       for i in range(1, len(grid)):
  11.         h = min(i, len(grid) - i)  # Shortest height.
  12.         if np.sum(grid[i - h : i] != grid[i : i + h][::-1]) == num_diff:
  13.           reflections.append((axis, i))
  14.       grid = grid.T
  15.  
  16.     ((axis, i),) = reflections
  17.     total += i * [100, 1][axis]
  18.  
  19.   return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement