Skip to content

Instantly share code, notes, and snippets.

@damionjunk
Created November 27, 2011 19:19
Show Gist options
  • Save damionjunk/1398012 to your computer and use it in GitHub Desktop.
Save damionjunk/1398012 to your computer and use it in GitHub Desktop.
Naively balance a string.
(defn str-b-balance
"Naive bracket balance in the provided string."
[s & {:keys [ls rs] :or {ls \[ rs \]}}]
(let [bc (b-closers s)]
(reduce (fn [st ch]
(if (= ls ch) (str ch st) (str st ch)))
s
bc)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment