|
|
@ -2,7 +2,7 @@
|
|
|
|
(def to-score {\) 1 \] 2 \} 3 \> 4})
|
|
|
|
(def to-score {\) 1 \] 2 \} 3 \> 4})
|
|
|
|
|
|
|
|
|
|
|
|
(defn check-line [input]
|
|
|
|
(defn check-line [input]
|
|
|
|
(loop [open [] in input]
|
|
|
|
(loop [in input open '()]
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
(empty? in)
|
|
|
|
(empty? in)
|
|
|
|
(map to-closing open)
|
|
|
|
(map to-closing open)
|
|
|
@ -11,20 +11,18 @@
|
|
|
|
nil
|
|
|
|
nil
|
|
|
|
:else
|
|
|
|
:else
|
|
|
|
(recur
|
|
|
|
(recur
|
|
|
|
(if (contains? #{\{ \( \[ \<} (first in))
|
|
|
|
|
|
|
|
(concat [(first in)] open)
|
|
|
|
|
|
|
|
(rest open))
|
|
|
|
|
|
|
|
(rest in)
|
|
|
|
(rest in)
|
|
|
|
))))
|
|
|
|
(if (contains? #{\{ \( \[ \<} (first in))
|
|
|
|
|
|
|
|
(conj open (first in))
|
|
|
|
|
|
|
|
(rest open)
|
|
|
|
|
|
|
|
)))))
|
|
|
|
|
|
|
|
|
|
|
|
(->> (slurp "./in")
|
|
|
|
(->> (slurp "./in")
|
|
|
|
(clojure.string/split-lines)
|
|
|
|
(clojure.string/split-lines)
|
|
|
|
(mapv vec)
|
|
|
|
(map (comp check-line vec))
|
|
|
|
(mapv check-line)
|
|
|
|
|
|
|
|
(filter some?)
|
|
|
|
(filter some?)
|
|
|
|
(mapv (partial reduce #(+ (* 5 %1) (to-score %2)) 0))
|
|
|
|
(map (partial reduce #(+ (* 5 %1) (to-score %2)) 0))
|
|
|
|
(sort)
|
|
|
|
(sort)
|
|
|
|
(#(get (vec %) (quot (count %) 2)))
|
|
|
|
(#(nth % (quot (count %) 2)))
|
|
|
|
(println)
|
|
|
|
(println))
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|