Skip to content

Instantly share code, notes, and snippets.

@sciyoshi
Last active December 17, 2020 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sciyoshi/3b0df201d087b4e5beda8a015e7f3699 to your computer and use it in GitHub Desktop.
Save sciyoshi/3b0df201d087b4e5beda8a015e7f3699 to your computer and use it in GitHub Desktop.
import numpy as np
from scipy.ndimage import convolve
LINES = open("inputs/day17").read().splitlines()
dims = 3 # 4 for part 2
steps = 6
front = 2 * steps + 1
filt = np.full((3,) * dims, 1)
filt[(1,) * dims] = 100
board = np.zeros((front,) * (dims - 2) + (front + len(LINES), front + len(LINES[0])), dtype=np.uint8)
for i, l in enumerate(LINES):
for j, c in enumerate(l):
board[(steps,) * (dims - 2) + (steps + i, steps + j)] = c == "#"
for i in range(steps):
conv = convolve(board, filt, mode="constant")
board[:] = (conv == 3) | (conv == 102) | (conv == 103)
print(np.sum(board))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment