Skip to content

Instantly share code, notes, and snippets.

@djtrack16
Created January 13, 2015 02:16
Show Gist options
  • Save djtrack16/4a904ef7b403ae1e9bfc to your computer and use it in GitHub Desktop.
Save djtrack16/4a904ef7b403ae1e9bfc to your computer and use it in GitHub Desktop.
all combos of well-formed parens of size O
(fn [o]
(let [f (fn q [s o c]
(set(remove #(or (coll? %) (nil? %))
(tree-seq
coll?
seq
(let[j (fn [sep coll] (clojure.string/join sep coll))
a (if (pos? o) (q (concat s "(") (dec o) (inc c)))
b (if (pos? c) (q (concat s ")") o (dec c)))]
(if (and (zero? o) (zero? c))
(j "" s)
[a b]))))))] (f "" o 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment