From ae6798da1c29934146f2e7b08678b7bf7b184b34 Mon Sep 17 00:00:00 2001 From: Brian Chu Date: Sat, 8 Jan 2022 00:03:44 -0800 Subject: solution for day 18 --- day18.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 day18.py diff --git a/day18.py b/day18.py new file mode 100644 index 0000000..ec8ac9b --- /dev/null +++ b/day18.py @@ -0,0 +1,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) -- cgit 1.4.1-2-gfad0