Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day11(s, *, part2=False):
- expand = 1_000_000 if part2 else 2
- grid = np.array([list(line) for line in s.splitlines()])
- coords = np.argwhere(grid == '#').T
- def process(values):
- total = last_value = num = 0
- for value, group in itertools.groupby(values):
- spacing = 1 + (value - last_value - 1) * expand
- total += num * (len(values) - num) * spacing
- num += len(list(group))
- last_value = value
- return total
- return process(coords[0]) + process(sorted(coords[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement