Last active
December 17, 2020 05:53
-
-
Save sciyoshi/3b0df201d087b4e5beda8a015e7f3699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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