summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--day18.py16
1 files changed, 16 insertions, 0 deletions
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)