about summary refs log tree commit diff
path: root/day09.clj
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-12-10 21:27:11 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-12-10 21:27:11 +0100
commit6b8523c3caebdc30f0c2b97efa95d128a95e1744 (patch)
treefd05e3684f822d1a5597745c9bf625633ec3172c /day09.clj
parenta521c98193a01927f5d4f7aa245a6fc9ca7d8ad9 (diff)
downloadadventofcode2020-6b8523c3caebdc30f0c2b97efa95d128a95e1744.tar.gz
adventofcode2020-6b8523c3caebdc30f0c2b97efa95d128a95e1744.tar.xz
adventofcode2020-6b8523c3caebdc30f0c2b97efa95d128a95e1744.zip
day09
Diffstat (limited to 'day09.clj')
-rw-r--r--day09.clj21
1 files changed, 21 insertions, 0 deletions
diff --git a/day09.clj b/day09.clj
new file mode 100644
index 0000000..45f515b
--- /dev/null
+++ b/day09.clj
@@ -0,0 +1,21 @@
+(def data
+  (->> (slurp "day09")
+       (clojure.string/split-lines)
+       (map read-string)
+       vec))
+
+(defn is-sum [n & ms]
+  (some #{n} (for [x ms y ms]
+               (+ x y))))
+
+(def part1
+  (some #(if-not (apply is-sum (reverse %))
+           (last %))
+        (partition 26 1 data)))
+part1 ; => 138879426
+
+(some (fn [xs]
+        (let [s (take-while #(<= % part1) (reductions + xs))]
+          (if (some #{part1} s)
+            (apply + (apply (juxt min max) (take (count s) xs))))))
+      (iterate rest data)) ; => 23761694