From: Clyne Sullivan Date: Wed, 15 Dec 2021 03:04:10 +0000 (-0500) Subject: checking out 2020 X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=d1bb4af495094eec997cbe7e99a382877c7c7b5a;p=clyne%2Fadvent-of-code.git checking out 2020 --- diff --git a/year2020/day1/part1.clj b/year2020/day1/part1.clj new file mode 100644 index 0000000..100c6d3 --- /dev/null +++ b/year2020/day1/part1.clj @@ -0,0 +1,9 @@ +(require 'clojure.set) + +(->> (slurp "./in") + clojure.string/split-lines + (map read-string) + ((juxt set (comp set #(map (partial - 2020) %)))) + (apply clojure.set/intersection) + (apply *) + (println)) diff --git a/year2020/day1/part2.clj b/year2020/day1/part2.clj new file mode 100644 index 0000000..0b6ef9d --- /dev/null +++ b/year2020/day1/part2.clj @@ -0,0 +1,20 @@ +(require 'clojure.set) + +(defn find-sum [sum lst] + (->> lst + ((juxt set (comp set #(map (partial - sum) %)))) + (apply clojure.set/intersection) + (vec))) + +(->> (slurp "./in") + clojure.string/split-lines + ((comp set (partial map read-string))) + ((fn [lst] + (reduce + #(let [fnd (find-sum (- 2020 %2) (clojure.set/difference lst #{%2}))] + (if (empty? fnd) %1 [%2 fnd])) + [] + lst))) + flatten + (apply *) + (println))