Skip to content

Instantly share code, notes, and snippets.

@sciyoshi
Created December 20, 2021 05:28
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/ff09226135bfcac872ecb05b35c223ac to your computer and use it in GitHub Desktop.
Save sciyoshi/ff09226135bfcac872ecb05b35c223ac to your computer and use it in GitHub Desktop.
import numpy as np
from scipy.ndimage import convolve
lines = INPUT.splitlines()
alg = [i for i, c in enumerate(lines[0]) if c == "#"]
img = np.pad(np.array([[int(c == "#") for c in l] for l in lines[2:]]), ((50, 50), (50, 50)))
rot = np.array([[1, 2, 4], [8, 16, 32], [64, 128, 256]])
for i in range(50):
img = np.isin(convolve(img, rot, mode="constant", cval=i % 2), alg).astype(int)
if i == 1:
print("part1", img.sum())
print("part2", img.sum())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment