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.

27 lines
615 B
Clojure

3 years ago
(def to-closing {\{ \} \( \) \[ \] \< \>})
(def to-score {\) 3 \] 57 \} 1197 \> 25137})
(defn check-line [input]
3 years ago
(loop [in input open '()]
3 years ago
(cond
(empty? in)
nil
(and (contains? #{\} \) \] \>} (first in))
(not= (to-closing (first open)) (first in)))
(first in)
:else
(recur
(rest in)
3 years ago
(if (contains? #{\{ \( \[ \<} (first in))
(conj open (first in))
(rest open)
)))))
3 years ago
(->> (slurp "./in")
(clojure.string/split-lines)
3 years ago
(map (comp to-score check-line vec))
3 years ago
(filter some?)
(apply +)
(println))