Skip to content

Instantly share code, notes, and snippets.

@mfikes
Created December 11, 2017 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/57c1b666c30bb5fd98b235df87b5c189 to your computer and use it in GitHub Desktop.
Save mfikes/57c1b666c30bb5fd98b235df87b5c189 to your computer and use it in GitHub Desktop.
(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