about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-12-26 13:35:41 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-12-26 13:35:41 +0100
commit7b7d4044036e7797f99be26cd7b324d8f0f1f9b9 (patch)
tree198da2c7c32afd8c0826306a020e95f169f5e15e
parent1047a8d0c88fc686fb3aba8495167b97a80bab8d (diff)
downloadadventofcode2020-7b7d4044036e7797f99be26cd7b324d8f0f1f9b9.tar.gz
adventofcode2020-7b7d4044036e7797f99be26cd7b324d8f0f1f9b9.tar.xz
adventofcode2020-7b7d4044036e7797f99be26cd7b324d8f0f1f9b9.zip
day25 HEAD master
-rw-r--r--day252
-rw-r--r--day25.clj29
-rw-r--r--day25.ijs2
3 files changed, 33 insertions, 0 deletions
diff --git a/day25 b/day25
new file mode 100644
index 0000000..fe7ecff
--- /dev/null
+++ b/day25
@@ -0,0 +1,2 @@
+1614360
+7734663
diff --git a/day25.clj b/day25.clj
new file mode 100644
index 0000000..6fd8e55
--- /dev/null
+++ b/day25.clj
@@ -0,0 +1,29 @@
+(def data
+  (->> (slurp "day25")
+       clojure.string/split-lines
+       (map read-string)))
+
+; (def data '(5764801 17807724))
+
+(defn gen [m]
+  (->> 1
+       (iterate #(mod (* % m) 20201227))
+       (map-indexed vector)))
+
+(def iters
+  (some #(if (= (second %) (first data))
+           (first %))
+        (gen 7)))
+
+(second (nth (gen (second data)) iters))
+;; => 5414549
+
+(defn m* [a b]
+  (mod (* a b) 20201227))
+
+(loop [pub 1 key1 1 key2 1]
+  (cond
+    (= pub (first data)) key2
+    (= pub (second data)) key1
+    :else (recur (m* pub 7) (m* key1 (first data)) (m* key2 (second data)))))
+;; => 5414549
diff --git a/day25.ijs b/day25.ijs
new file mode 100644
index 0000000..6f825b7
--- /dev/null
+++ b/day25.ijs
@@ -0,0 +1,2 @@
+'c d m' =: 1614360 7734663 20201227
+d m&|@^ <:#(m|7*])^:(c&~:)^:a:1