diff options
-rw-r--r-- | day25 | 2 | ||||
-rw-r--r-- | day25.clj | 29 | ||||
-rw-r--r-- | day25.ijs | 2 |
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 |