Advertisement
hhoppe

Advent of code 2023 day 11

Dec 10th, 2023 (edited)
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. def day11(s, *, part2=False):
  2.   growth = 1_000_000 if part2 else 2
  3.   grid = np.array([list(line) for line in s.splitlines()])
  4.   galaxies = np.argwhere(grid == '#')
  5.   occupied = [{galaxy[c] for galaxy in galaxies} for c in range(2)]
  6.   total = 0
  7.   for galaxy1, galaxy2 in itertools.combinations(galaxies, 2):
  8.     for a, b, occ in zip(galaxy1, galaxy2, occupied):
  9.       total += sum(1 if x in occ else growth for x in range(min(a, b), max(a, b)))
  10.   return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement