about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-12-25 17:51:49 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-12-25 17:51:49 +0100
commitceb09f9791e37f5c7fc422c9f848de09d58a7337 (patch)
tree5e4c9a3ab4c4d851ce53e1e008fb6886e0ec4e61
parent01eae09c06e680f5ad9c7845d6ad33bcac458330 (diff)
downloadadventofcode2021-ceb09f9791e37f5c7fc422c9f848de09d58a7337.tar.gz
adventofcode2021-ceb09f9791e37f5c7fc422c9f848de09d58a7337.tar.xz
adventofcode2021-ceb09f9791e37f5c7fc422c9f848de09d58a7337.zip
day24
-rw-r--r--day24252
-rw-r--r--day24.bqn22
-rw-r--r--day24.clj52
3 files changed, 326 insertions, 0 deletions
diff --git a/day24 b/day24
new file mode 100644
index 0000000..81cc5f4
--- /dev/null
+++ b/day24
@@ -0,0 +1,252 @@
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 10
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 12
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 12
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 7
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 10
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 8
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 12
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 8
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 11
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 15
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -16
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 12
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 10
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 8
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -11
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 13
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -13
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 3
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 13
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 13
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -8
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 3
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -1
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 9
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -4
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 4
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -14
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 13
+mul y x
+add z y
diff --git a/day24.bqn b/day24.bqn
new file mode 100644
index 0000000..b1df09a
--- /dev/null
+++ b/day24.bqn
@@ -0,0 +1,22 @@
+# port of https://github.com/cettt/Advent_of_Code2021/blob/master/day_24.R
+str←•Import"bqn-libs/strings.bqn"
+Diff ← (¬∘∊/⊣)
+
+d←{•BQN⊑⌽" " str.Split 𝕩}¨ 4‿5‿15 ⊏⎉1 14‿∘⥊•FLines"day24"
+
+x1←eqidx←/9≥1⊏˘d
+x2←⟨⟩
+x1minmax←⟨⟩
+x2minmax←⟨⟩
+
+{
+  x2 ∾↩ newmatch ← ⌈´ (↕𝕩) Diff x1∾x2
+  b ← (newmatch‿2⊑d) + 𝕩‿1⊑d
+  minmax ← (0 (<⋈>) b) + (⌊´⋈⌈´) / (>⟜0 ∧ <⟜10) b+↕9
+  x2minmax ∾↩ <minmax
+  x1minmax ∾↩ <minmax+b
+}¨eqidx
+
+res←(x1∾˘>x1minmax)∾(x2∾˘>x2minmax)
+
+•Show '0'+⌽⍉1↓˘(⍋0⊏˘res)⊏res
diff --git a/day24.clj b/day24.clj
new file mode 100644
index 0000000..45e2f0a
--- /dev/null
+++ b/day24.clj
@@ -0,0 +1,52 @@
+(ns org.vuxu.aoc2021.day24
+  (:require [clojure.string :as str]
+            [clojure.core.match :refer [match]]
+            [clojure.set :as set]))
+
+(def data
+  (->> (slurp "day24")
+       str/split-lines
+       (map #(str/split % #" "))
+       (map (partial mapv #(if (re-matches #"-?\d+" %) (parse-long %) %)))))
+
+(def params
+  (for [part (partition (/ (count data) 14) data)]
+    [(last (nth part 5))
+     (last (nth part 15))]))
+
+(defn run [z d c1 c2]
+  (let [con (not= (+ (mod z 26) c1) d)
+        z (if (neg? c1) (quot z 26) z)
+        z (if con (+ (* 26 z) d c2) z)]
+    z))
+
+(def part1
+  (->> (reduce (fn [acc [c1 c2]]
+                 (prn [c1 c2 (count acc)])
+                 (into (sorted-map)
+                       (for [[z v] acc
+                             d (range 1 10)
+                             :when (<= z (* 26 26 26 26 26))]
+                         [(run z d c1 c2) (conj v d)]))
+                 )
+               {0 []}
+               params)
+       (#(get % 0))
+       (apply str)))
+;; => "96299896449997"
+
+(def part2
+  (->> (reduce (fn [acc [c1 c2]]
+                 (prn [c1 c2 (count acc)])
+                 (into (sorted-map)
+                       (for [[z v] acc
+                             :let [z (- z)]
+                             d (reverse (range 1 10))
+                             :when (<= z (* 26 26 26 26 26))]
+                         [(- (run z d c1 c2)) (conj v d)]))
+                 )
+               (sorted-map 0 [])
+               params)
+       (#(get % 0))
+       (apply str)))
+;; => "31162141116841"