aboutsummaryrefslogtreecommitdiffstats
path: root/day10/part1.clj
diff options
context:
space:
mode:
Diffstat (limited to 'day10/part1.clj')
-rw-r--r--day10/part1.clj22
1 files changed, 9 insertions, 13 deletions
diff --git a/day10/part1.clj b/day10/part1.clj
index 1424fd8..60ed1e6 100644
--- a/day10/part1.clj
+++ b/day10/part1.clj
@@ -3,19 +3,15 @@
(defn check-line [input]
(loop [in input open '()]
- (cond
- (empty? in)
- nil
- (and (contains? #{\} \) \] \>} (first in))
- (not= (to-closing (first open)) (first in)))
- (first in)
- :else
- (recur
- (rest in)
- (if (contains? #{\{ \( \[ \<} (first in))
- (conj open (first in))
- (rest open)
- )))))
+ (when-let [c (first in)]
+ (if (some->> (#{\} \) \] \>} c) (not= (first open)))
+ c
+ (recur
+ (rest in)
+ (if-let [op (to-closing c)]
+ (conj open op)
+ (rest open)
+ ))))))
(->> (slurp "./in")
(clojure.string/split-lines)