summary refs log tree commit diff stats
path: root/day20.py
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2021-12-19 22:57:37 -0800
committerBrian Chu <brianmchu42@gmail.com>2021-12-19 22:57:37 -0800
commitd4f482804b9777768fa4f9fedde0cd549578502b (patch)
tree211098ceaad6046234e0f55fe86dc539f791d4a4 /day20.py
parent04d85bf194d50f8da584a8c657d7490649befb7c (diff)
downloadAdventOfCode2021-d4f482804b9777768fa4f9fedde0cd549578502b.tar.gz
catch up on solutions up to day 20
Diffstat (limited to 'day20.py')
-rw-r--r--day20.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/day20.py b/day20.py
new file mode 100644
index 0000000..74ca7fd
--- /dev/null
+++ b/day20.py
@@ -0,0 +1,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())