Created
January 13, 2015 02:16
-
-
Save djtrack16/4a904ef7b403ae1e9bfc to your computer and use it in GitHub Desktop.
all combos of well-formed parens of size O
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
(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