about summary refs log tree commit diff
path: root/day09.clj
diff options
context:
space:
mode:
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