From 6b8523c3caebdc30f0c2b97efa95d128a95e1744 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Thu, 10 Dec 2020 21:27:11 +0100 Subject: day09 --- day09.clj | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 day09.clj (limited to 'day09.clj') 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 -- cgit 1.4.1