aboutsummaryrefslogtreecommitdiffstats
path: root/year2020/day1/part2.clj
blob: 0b6ef9d2a8df3bfeda53b452251bb539c98c42e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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))