blob: 2bef6964fb520e558e8345482f5caee21aef9f2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
(def to-closing {\{ \} \( \) \[ \] \< \>})
(def to-score {\) 3 \] 57 \} 1197 \> 25137})
(defn check-line [input]
(loop [open [] in input]
(cond
(empty? in)
nil
(and (contains? #{\} \) \] \>} (first in))
(not= (to-closing (first open)) (first in)))
(first in)
:else
(recur
(if (contains? #{\{ \( \[ \<} (first in))
(concat [(first in)] open)
(rest open))
(rest in)
))))
(->> (slurp "./in")
(clojure.string/split-lines)
(mapv vec)
(mapv check-line)
(filter some?)
(mapv to-score)
(apply +)
(println))
|