Created
February 5, 2009 19:08
-
-
Save gnuvince/58924 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
(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