From e294402b6a64c2d09d6bc68f868c43f3ba63ea52 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 12 Dec 2020 21:20:14 +0100 Subject: day10 --- day10 | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ day10.clj | 31 +++++++++++++++++++++ day10.ijs | 3 +++ 3 files changed, 126 insertions(+) create mode 100644 day10 create mode 100644 day10.clj create mode 100644 day10.ijs diff --git a/day10 b/day10 new file mode 100644 index 0000000..ccf88b7 --- /dev/null +++ b/day10 @@ -0,0 +1,92 @@ +17 +110 +146 +144 +70 +57 +124 +121 +134 +12 +135 +120 +19 +92 +6 +103 +46 +56 +93 +65 +14 +31 +63 +41 +131 +60 +73 +83 +71 +37 +85 +79 +13 +7 +109 +24 +94 +2 +30 +3 +27 +77 +91 +106 +123 +128 +35 +26 +112 +55 +97 +21 +100 +88 +113 +117 +25 +82 +129 +66 +11 +116 +64 +78 +38 +99 +130 +84 +98 +72 +50 +36 +54 +8 +34 +20 +127 +1 +137 +143 +76 +69 +111 +136 +53 +43 +140 +145 +49 +122 +18 +42 diff --git a/day10.clj b/day10.clj new file mode 100644 index 0000000..255ba27 --- /dev/null +++ b/day10.clj @@ -0,0 +1,31 @@ +(def data + (->> (slurp "day10") + (clojure.string/split-lines) + (map read-string) + vec)) + +(def diff + (->> data + (#(cons 0 %)) + (#(cons (+ 3 (reduce max %)) %)) + sort + (#(map - (rest %) %)))) + +(->> diff + frequencies + (#(map % [1 3])) + (apply *)) ; => 1820 + +(->> diff + (partition-by identity) + (filter #(= (first %) 1)) + (map count) + (map #(inc (* (dec %) (/ % 2)))) ; http://oeis.org/A000124 + (apply *)) ; => 3454189699072N + +;; => (1 3 1 1 1 3 1 1 3 1 3 3) +;; 1 4 2 1 +;; +;; => (1 1 1 1 3 1 1 1 1 3 3 1 1 1 3 1 1 3 3 1 1 1 1 3 1 3 3 1 1 1 1 3) +;; 7 7 4 2 7 1 7 +;; 19208: 2 2 2 7 7 7 7 diff --git a/day10.ijs b/day10.ijs new file mode 100644 index 0000000..9e82b15 --- /dev/null +++ b/day10.ijs @@ -0,0 +1,3 @@ +d=:|2-/\3,0x,/:~".;._2(1!:1)<'day10' +*/#/.~d +*/>:(<:*-:)@#;._1 d -- cgit 1.4.1