Skip to content

Instantly share code, notes, and snippets.

@gnuvince gnuvince/gist:58924
Created Feb 5, 2009

Embed
What would you like to do?
(def opening-brackets "({[<")
(def closing-brackets ")}]>")
(def brackets (reduce #(apply assoc %1 %2) {}
(map vector opening-brackets closing-brackets)))
(defn- check-aux [[x & xs] stack]
(if x
(cond (some #{x} opening-brackets) (recur xs (conj stack (brackets x)))
(some #{x} closing-brackets) (if (= x (peek stack))
(recur xs (pop stack))
false)
:else (recur xs stack))
(empty? stack)))
(defn check-brackets [s]
(check-aux s []))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.