Skip to content

Instantly share code, notes, and snippets.

@damionjunk
Created November 27, 2011 03:57
Show Gist options
  • Save damionjunk/1396939 to your computer and use it in GitHub Desktop.
Save damionjunk/1396939 to your computer and use it in GitHub Desktop.
Clojure bracket balanced? function
(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