about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--day20102
-rw-r--r--day20.bqn5
-rw-r--r--day20.clj36
3 files changed, 143 insertions, 0 deletions
diff --git a/day20 b/day20
new file mode 100644
index 0000000..f0b3a0b
--- /dev/null
+++ b/day20
@@ -0,0 +1,102 @@
+#####.#.##.####.#....#.###.##.###.#..#.#...##....#.#.##..#...#..##.##.####.#....##.#.#......###..#.#.#...##.#...###...#.#...##....####....#...#.####..#.#.####....####..#..#..#....###...#..#.###.##..##..####....####.###..#.#.##.#.###.##....####.#####.##.#.#...##.######....##...#####.##..###.####.#.##..##...#.#..#.#.#.....#..#..##..##..######..#..#..##..#.##.#..###.#....#.#.#.#.#.#..#.##.#.#....###.#.#..#....#.##..##.##...#..#####.###.......###.###.#..#.##.######.#######.##..##.##..#.##......#####.#.....#..#.
+
+.##..##...#...#...#.##.###.##.......#....#.#..#...###.##.###..#.##.###...#..#..######...#####.#....#
+#.......###..##.#.#.....###.#..#..#.#..#...#..##.#.#.#.#.#.#.#.#..####.#.#.#.#....####.##.#.#.#.###.
+...###..#..##.#.##..#.#..###...#..#.###.#.###....##...####..#.#.#.###.#.#..##..#.#...#########.##.#.
+.#...##..#.####..#.#.#..##.#.#.##.##..##.#..#.#..##.##...#..#.#..#..#....##....###.##.###..#.#..####
+..###..#.#.#.#.#..#...##......#..###.#.#..##....#.#####....####..##..####.#.####..####...####.#..#..
+.##.##.#.#..#.#.##.######.##..###....#####.#...#..#...##.######..#.##.###...##.#.#.#.#.#.......#.#.#
+.......#..#..#.##.###....#.#..##..#.#..#...#..##.#..#.#.#...######.####..###...###.#....#...#..#.###
+.####.####...........#.#....#.#.#...#.###.##.##...#.####...##..###..###..###.##...#.##.##.#.####..#.
+######.#....####.#.##..#.##.#.######...##.#...##.#.###..##....#.......##.#.#.#.####.#.#.....#.#...##
+#.##..##.....#.#.###..##..##..###....##..##.#.#..#...####.#.#.###.##.##.#.####.#.###.#..#...#.##..##
+##.###.###.#....###.####.##..##..#.#.#.#.#...#....###..#..#..##...#.##..##..#.#.#######...###...##.#
+##.##....#...##......#.#....#...##.#.#..#....#.###.#..###.#..#..###.##.....#...#.#.#.#.##...#..##...
+.#..#..#..#####....####..#.###.#.#.##..#......####..###.##...##.#..#..........#..##.##...###.##..##.
+........##..#..#...####..#.##.#.#....#..#..#......#.##..#.##...##.#..........#.#.#.#.#.#......######
+..#.##.....###...###.#.##.#######.###.###.####.##.#..##..#...#...#.#####....##...#.####..########..#
+#.#..####..#....#..###..#.#.##...#.###.###..#.....#....#...###.###.######.##.##.#....##.#.##.###...#
+#..#.....#.#.#.#.#....#...###..##..#..#.##...#.###..#......##....#.##.###.#.#.#.###.##.####.#..#..#.
+.##....#.#.###.##.###.#.##....##.##.#..#.##...##...###....###..#..#.###.##.#..#.#.#.##.#...#.##.#.#.
+..####.#.##.##.#.#.#.....##.#...##...##.#######.###...#..##...#.###..#..#..###..##.#.##.......#.#.##
+#..#####..####.#.###.##.#.#.#.......#..##.####.#...#.###.###..##.....##..#####..####....####.##.#.#.
+.#...##.#.###.#.########......#...###...##...##.##..#.#.#...##...#.#.#..#######.###...###.#.#.#.#...
+..#..##...#.###.#...#..#.#.##.#.#..#...###..##...##..#.##.##.##..#.#.....#.#######...#..##.###.#..##
+.........#...##..#...##...##.#.....#.#..#..#..###......#.#..#.###.###.#...#.###.####.....#....#.#.##
+.##.###.######..#######..#...#...#..#.#.##...##.###.#.##.##..##.###.#.###.#.####.###....#.#.#..#....
+.#.##...####.#.##.#..##.##..##.#.##...#..##...#####...###.##.##..#..#......#####.....#.#..##..#..#..
+#..#####.###...#..#.....#.##.#..##...#.#...##....####.#..#..####..#..#..##...###...###.######..##...
+##...#...####...###.#.######....##.##..#####.#...###..#..#.#..#...###.#.#.##.###.#...##....#.##...#.
+..#.#..##..#.#.#.#..##..#.#..#.##.#.#..#..#.#.#.####..#.........#.####..##.#.#.#.##..##.#..##..#....
+###.......#.##..#.#.##.#####..#..#..#####.###.#.....##.#..#..#..###..#######......####....#....#...#
+##........#...##..#####.###.#....#.#.#.##.#####...#.##..###...######....##.##.#...###.##.#..##..####
+..##..##...#.#..####.#.#............#.#...#.#....##..#..########.#.##.##.##.#.#.#.###.##.#.######...
+#.#.##.##..#.##..##..#.##.#..#.#.#.#.#####.#.####.###....##.#..##..#...#.#...####..##.#.#..###.#..##
+...##.##..#..#####..#..#.#.#.......#.##..###.##.##.#..###....##..#....####.##.#..#..#.#...#######.##
+.##.#.#...####...#.#..#########.#.###..###..#...###.##.#.#.##....##..#.#####..#.##.......#.#.#..##..
+#...#.#...###.#.#.......##......#####..#....###..##.#.#.....#....#...#.###.#.##.####.....#..###.#.##
+##.#####.###.....###..#.##..####...###.#.##.######...#####...#.#..##.#.#####.#####..#..##.#..#.#..##
+#.##.########.#.###...#.#.#.###.###..##.##.#....##..#.#.##.#.......#.######.###..##.####.##.####.###
+###.##..#.#...#...###.....#..#....#.#....###....##...###.#...##......#.##..##..####.###.#.#......##.
+.##..##..##..####.##..#.#####.####.#.#.##..#.......#...#..######.#####.#..#.#..##....#.##.#...#...#.
+..##........#..#.#.#.#.###.###.#####...##...#.#.##.#.#...###...##..#.##.###.#....#.###..##.##.####.#
+.##.#....#..#..##.#.####.##.####..##....##..#..#.#.#.####.#.##.##.#.#.##..#.##.##.###.##.#....#.#.#.
+.##..###....#..#.##....#.....#.##.....#.##.#.##.###.#.#..#...#..##.##...##.#.###.###..#.###...#..##.
+##.##..#.#.##...#.###...#.##.#.....#..#..#.##...#.##...#####.......#.###..#.##.##.###.#.#....#.###..
+##.#####....#.....#.#...##.#.#..##...#.#.##...#####...........#.####.....####..#..##...####..####.#.
+#.##...#.##.####.#.#.#.##.#....###.##......###...#.##.#...#####.##..#.##.##...#....##.##.##.###..#.#
+#..#..#.###.##..##..#######..####...#####.##.#.#.#...#..###.#..#.#.#..##..##...##..####.###.##.###..
+.###.##....##..#.#..####...#.#.#..#.#..#.#.###....##........#.####.#...#...#..####.#.....#.##....###
+#..#####..##..####.#####.###.#.#..#..#.#.#.##...##...####.#.#.###.....#..##.#.##.##......#...#.#.##.
+#####.##.###....#...#..###..#..#..#####..#..#..###.####..##....##..####.##.##.##.##.#.#..#..##..##..
+#.#..####..#..###..###.#....#.#..#..#..#...##...#####.....###...#.#.....#####.###....#.###...#####..
+...........####..##.#.####.####.#.##.#.#.#.##...###.#.##.##.####.....##...###....#.#..#.....##.#.#.#
+#......##...##.##..#.##.#.##..#..##.###....##...##....#...##.#.##.#..#....####..#.##...####.....##..
+########..######.#.##..##.#...#...#.##.##...#..##..##..##..#.##...#.##.#.###.###.#.#.#.#..#..#..##..
+.#.#..#######.....##..#.##.#..###..##.#..#.#.....###.#...#..###.##..####...##..#.#....###..##.#..#.#
+..###..#.##.#.#.....#..#..####..###..#..#...#.........#..#####.####..####...##...#.#.##.#.#.##.###.#
+.#.....##.#..######....#.#.#.###.#.#...#.##.....###.##.#..#.##.##.#....###..###.#.#.###..####.#....#
+.#..#.......#.#.##...........#...###.#..##...##..#.#...##.####..####......#.#####..######.#.....####
+#..###..##..#.##.####..########.#.##..######..####..#..##.#.#.#.#.###.##.#..##.#..###.##.....#..##..
+...######....#.#..#######.#.##.##.#.#..###......##..#..#.####.....#..###.#.###.#...###.#.#..#..#..##
+###.#..#.......##.#..##..########.###..####.##..#.###..#.....#...##.....##..#.#.#.#.####...####.#..#
+##.##...##.#.#..##########....#..#..#.##....#..#..##.####...#......##..#.##..#..####.#.##..##.#.##.#
+.#.####.###....#.#....####...###.###..#.#...#..#.####.....#.#.#..##.....#.##...###.####..#.##.#...#.
+#..##.#.#.###.......#.##.....##.###.##..#.###.##.#.########.###.#.###.#.....####..##.#.#.###.#####.#
+#.###.#..###...##....#.....#.####.#.#...###..##.#..##....#...###.#.#.#.#..#..##..#.####...#......##.
+.#...#..##.###..#.#.#..##.##..###..#.####.##.#.##.###.#...###.#.###....#.###.....#.#..###.#..#####..
+##..##.#.#.#.#..##..####..#..#..#.##.##.#..#..###...####...#..###....#.###.#.#####.##.###.#.###...#.
+##.....##..#.#..####....##..######...#.......#.##..##....#.#......#..####..###...###....#######.#..#
+..###..###..##.####.#.....#.##..#..##..###..#.....##..#.#.........#####.....####.##.#.#...#.####.###
+....###..##.######...#.#.#.#..##..#.##....##..#.....####.#####..#.#..#.#...##...#.##.###.#..######.#
+.....#......##..#.#...#..##.##....#####..##.#.#.......#..##.#.#..###.####.##..#.#.#.##....#####.....
+#####.#####.#.##....###......##...##..####..##..###.##..#..##..#....#.######.#####....###...#.##..#.
+.######..###.#.####...#.##.#.##.##..#..#..######.##.###.##..#####..#.####.####.##.###...#....#####..
+..##.#.##.#.###.#.##...##.##..##.###..#.....#..#.###...####....#.##.#.#...#####...#.#######.....##..
+###...##.#...#.####.....#........##..#.#.####....#####.#.##...##..########.#...#..###.#..#.#..#.#.##
+.#.#.##.####..#####...#..#..###..#.....####.#.#..#.#...#...#....#...####.##....##..#.###.###.#....#.
+#.#...#.##...##.##..#..#..#....##..#...###.#...#.#.#.###...#...#..###...#.#.#.##.#####....##....###.
+..#####.####.##.##.##.##...#########.###.##...#.#...####....#..#.####...#...#####....#.#...#..#.#...
+.##...#.#.#.#..#.#.#.#..##..#..###.#.....#.#.#.#...#.##.##..#.####.######.##.#.#..#.###.#......#.##.
+##.........###.....#.######.##.....##..####.#.##.####.#..####.##.#.#.#.######.#####....#.#######..#.
+###.##.####.#.....#.#..#.###..###..#..#..#.##..##..#....##...##.#..#.#.#...#..###.#.#..#....#.#.#.##
+#.#..###..##....##...#########..####.##.#..#..#.........##....##.#..#.......###..#....#.##.#...#.#.#
+#..###..####.#..###.#.###..#.......###...#####...###.#...#....##..#..##.#.#.#.#.##.##...#.##....#.#.
+###..###...######.......#.#....#####.....##.#..#....#.#.##..#..#..######..#..##.##.#.##.#.#.#####.##
+..#.##.#.##.#..##...###.#####..##........#.#..#.###..##....#..####..#..###...#.#.##.##...##..##..###
+..##.#...#...#..###.####..##..#....###.#####...##.##........###....#...####.#....#.#####.#...####.##
+#....#..#...##..#..######..#.##...#.#..#...##.#.#.#.#.###..##.##.####.#.##.##..#...#...###.##.#..##.
+.#..###...###.#...##.####.#........#......#..#.#..######.###..#.##..#.#.#.###.######.##.#.#..#..#.##
+#...##....###.#.#....###..#..#...#.##..#.###.......##.##....#..####.##.#.##.#.####.#..#.#..##.#..##.
+#.#...#..#.######.#.#.#....#.###.#.#.###.#.##.##.#.#.##..#.###.###.######..#...####.#.#.##...####.#.
+#.....#.....#######.#.#..##.#..#.#.#......#.#.#.##...#...##########...##.###..##..#......##.#..#....
+..##.##.#..#####..#...#.#..#...#....#...##..#####.#..#..#..##.##.#...#.#..####...#.##...#.#.##.#.##.
+##..######...#.##..#.#.#..#..####....#.#....##.#.#....#.###.#..##.####....#.......##..##.#....#..##.
+#######.#####.#..##..#.#####.##.#.#.#..#.....#....######.####.##.##....#.##.#.#.#...##.#.#.#..#...##
+..#.##.###....#.#.#.#...#####.#..##..###....####...#..###...#.##.##.#.###.###.###.#...##.#.###.###.#
+..##..##.#.####.####...##..##.....#..##.#.##...#.#..##.##.##.##.###..########.#####.#..###.#.##.#..#
+.....##.#.#..###.##..#..#.#..###.#.####.#.....#.....##...##.##..##.#..###.###.#.....##..#.#..#......
+##...###.####..##.##.#..#######..##.##......#..#.########.#####...#.......##.###.##..#..#...#.######
+.#...##.#..###........####.#...###.#.###.#..#.###.##.#.#.#..##..#....#####......##.#.##...#.#.#.###.
+#.###....#.......##.#......#.##..#.....####....#...#.#.###.#####.#....##....#.#.###..#.#.##.#.##..##
+.####..##.###.....#.####....##....##..####.#####.#.#.#..###..#.##.#.##...#.##.##.#..##..###.#..#..##
diff --git a/day20.bqn b/day20.bqn
new file mode 100644
index 0000000..a9de76d
--- /dev/null
+++ b/day20.bqn
@@ -0,0 +1,5 @@
+enh‿img ← ('#'⊸=∘⊑ ⋈ >∘('#'⊸= 2⊸↓)) •Flines"day20"
+Step ← { enh ⊏˜ ((2⊸×+⊣)´∘⌽∘⥊)⎉2 3‿3 ↕ (2|𝕨 × ⊑enh) ⍉∘⌽∘(∾˘)⍟8 𝕩 }
+
+•Show +´⥊ img Step´ ⌽↕2
+•Show +´⥊ img Step´ ⌽↕50
diff --git a/day20.clj b/day20.clj
new file mode 100644
index 0000000..933460f
--- /dev/null
+++ b/day20.clj
@@ -0,0 +1,36 @@
+(ns org.vuxu.aoc2021.day20
+  (:require [clojure.string :as str]))
+
+(let [[enhance image] (str/split (slurp "day20") #"\n\n")]
+  (def enhance (mapv {\# 1 \. 0} enhance))
+  (def image (mapv (partial mapv {\# 1 \. 0}) (str/split-lines image))))
+
+(defn neighbour-offsets [x y]
+  (let [digits [-1 0 1]]
+    (for [dx digits
+          dy digits]
+      [(+ x dx) (+ y dy)])))
+
+(defn bin2int [bin]
+  (Integer/parseInt (apply str bin) 2))
+
+(defn tick [[image i]]
+  (let [background (if (zero? (enhance 0))
+                     0
+                     (mod i 2))]
+    [(vec (for [y (range -1 (inc (count image)))]
+            (vec (for [x (range -1 (inc (count (first image))))]
+                   (enhance (->> (neighbour-offsets y x)
+                                 (map #(get-in image % background))
+                                 bin2int))))))
+     (inc i)]))
+
+(def part1
+  (count (filter (complement zero?)
+                 (flatten (first (nth (iterate tick [image 0]) 2))))))
+;; => 5229
+
+(def part2
+  (count (filter (complement zero?)
+                 (flatten (first (nth (iterate tick [image 0]) 50)))))
+;; => 17009