summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2022-01-08 00:03:44 -0800
committerBrian Chu <brianmchu42@gmail.com>2022-01-08 00:03:44 -0800
commitae6798da1c29934146f2e7b08678b7bf7b184b34 (patch)
tree94d93e3f59c1eae13e036bd2d66a647d54555f86
parentff30ea3a9cde461aa8062a59457b3f17bfac38a6 (diff)
downloadAdventOfCode2016-ae6798da1c29934146f2e7b08678b7bf7b184b34.tar.gz
solution for day 18
-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)