Created
November 27, 2011 03:57
-
-
Save damionjunk/1396939 to your computer and use it in GitHub Desktop.
Clojure bracket balanced? function
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 bbalanced? [s] | |
"Is the provided string bracket balanced?" | |
(zero? (count (reduce (fn [v ch] | |
(if (= ch \[) | |
(conj v ch) | |
(if (= ch \]) | |
(if (= \[ (peek v)) | |
(pop v) | |
(conj v ch)) | |
v))) | |
[] | |
s)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment