Created
December 11, 2017 02:45
-
-
Save mfikes/57c1b666c30bb5fd98b235df87b5c189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn solve1 [input] | |
(loop [s (vec (reverse input)) | |
lvl 0 | |
garbage false | |
gc 0 | |
total 0] | |
(if-let [c (peek s)] | |
(if garbage | |
(case c | |
\> (recur (pop s) lvl false gc total) | |
\! (recur (pop (pop s)) lvl garbage gc total) | |
(recur (pop s) lvl true (inc gc) total)) | |
(case c | |
\{ (recur (pop s) (inc lvl) garbage gc total) | |
\} (recur (pop s) (dec lvl) garbage gc (+ total lvl)) | |
\< (recur (pop s) lvl true gc total) | |
(recur (pop s) lvl garbage gc total))) | |
[garbage gc lvl total]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment