day14: part2 final form

master
Clyne 3 years ago
parent 1faa513087
commit 140fc0f361

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

Loading…
Cancel
Save