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) diff --git a/day10/part2.clj b/day10/part2.clj index 49c9136..4dfaf3b 100644 --- a/day10/part2.clj +++ b/day10/part2.clj @@ -3,19 +3,15 @@ (defn check-line [input] (loop [in input open '()] - (cond - (empty? in) - (map to-closing open) - (and (contains? #{\} \) \] \>} (first in)) - (not= (to-closing (first open)) (first in))) - nil - :else - (recur - (rest in) - (if (contains? #{\{ \( \[ \<} (first in)) - (conj open (first in)) - (rest 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 + ))) (->> (slurp "./in") (clojure.string/split-lines)