You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
601 B
Clojure

3 years ago
(def to-closing {\{ \} \( \) \[ \] \< \>})
(def to-score {\) 1 \] 2 \} 3 \> 4})
(defn check-line [input]
3 years ago
(loop [in input open '()]
(if-let [c (first in)]
(when (or (nil? (#{\} \) \] \>} c)) (= (first open) c))
(recur
(rest in)
(if-let [op (to-closing c)]
(conj open op)
(rest open))))
open
)))
3 years ago
(->> (slurp "./in")
(clojure.string/split-lines)
3 years ago
(map (comp check-line vec))
3 years ago
(filter some?)
3 years ago
(map (partial reduce #(+ (* 5 %1) (to-score %2)) 0))
3 years ago
(sort)
3 years ago
(#(nth % (quot (count %) 2)))
(println))
3 years ago