add day 15

master
Clyne 3 years ago
commit aed41aa1f7

@ -10,8 +10,8 @@
(->> lines (->> lines
(drop 2) (drop 2)
(map #(str/split % #" -> ")) (map #(str/split % #" -> "))
(map (fn [[pair ltr]] (map (fn [[[a b] c]]
{pair (map str/join [[(first pair) ltr] [ltr (second pair)]])})) {(str/join [a b]) (map str/join [[a c] [c b]])}))
(reduce into) (reduce into)
)))))) ))))))
@ -28,13 +28,11 @@
(iterate #(grow-polymer % (second input)) (iterate #(grow-polymer % (second input))
(reduce #(update %1 %2 inc) blank-map (first input)))) (reduce #(update %1 %2 inc) blank-map (first input))))
(let [polymer (nth growth-seq 40) (let [final-polymer (nth growth-seq 40)
results (filter pos? letter-counts (reduce
(map #(Math/ceil (/ % 2)) (fn [r [k v]] (-> r (update (first k) + v) (update (second k) + v)))
(vals (zipmap (str/join (keys final-polymer)) (repeat 0))
(reduce final-polymer)
#(let [k (key %2) v (val %2)] (-> %1 (update (first k) + v) (update (second k) + v))) unique-counts (filter pos? (map #(Math/ceil (/ (val %) 2)) letter-counts))]
(zipmap (flatten (map (partial split-at 1) (keys polymer))) (repeat 0)) (println (- (apply max unique-counts) (apply min unique-counts))))
polymer))))]
(println (- (apply max results) (apply min results))))

@ -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))

@ -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))
Loading…
Cancel
Save