]> code.bitgloo.com Git - clyne/advent-of-code.git/commitdiff
checking out 2020
authorClyne Sullivan <clyne@bitgloo.com>
Wed, 15 Dec 2021 03:04:10 +0000 (22:04 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Wed, 15 Dec 2021 03:04:10 +0000 (22:04 -0500)
year2020/day1/part1.clj [new file with mode: 0644]
year2020/day1/part2.clj [new file with mode: 0644]

diff --git a/year2020/day1/part1.clj b/year2020/day1/part1.clj
new file mode 100644 (file)
index 0000000..100c6d3
--- /dev/null
@@ -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 (file)
index 0000000..0b6ef9d
--- /dev/null
@@ -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))