summary refs log tree commit diff stats
path: root/day20.py
blob: 74ca7fdbee379e0add3ea02855151b89f4fbe484 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
import numpy as np
from scipy.ndimage import convolve

with open('day20.txt') as data:
    algo, image = data.read().split('\n\n')
    algo = np.array(list(algo))
    algo = (algo == '#').astype(int)
    image = np.stack(list(map(list, image.strip().split('\n'))))
    image = (image == '#').astype(int)
    image = np.pad(image, (100, 100))

weights = 2 ** np.arange(9).reshape(3,3)
# part 1
for i in range(50):
    image = algo[convolve(image, weights)]
    if i == 1:
        print(image.sum())
print(image.sum())