summary refs log blame commit diff stats
path: root/day18.py
blob: ec8ac9bdfdff660bf1240df8c1badb0419f1c5d2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                                             
import numpy as np
from scipy.ndimage import convolve1d

with open('day18.txt') as data:
    line = np.array([char == '^' for char in data.read().strip()], dtype=int)

kernel = [1, 2, 4]

total = 100 - np.count_nonzero(line)
for i in range(400000 - 1):
    line = convolve1d(line, kernel, mode="constant", cval=0)
    line = (line==3) | (line==6) | (line==1) | (line==4)
    line = line.astype(int)
    total += 100 - np.count_nonzero(line)
    if i == 38: print(total)
print(total)