Created
December 12, 2008 15:29
-
-
Save robertpfeiffer/35157 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 powerset [list] | |
(if (empty? list) [list] | |
(let [[hd & tl] list ptl (powerset tl)] | |
(lazy-cat (map #(conj % hd) ptl) ptl)))) | |
(defn set-powerset [a-seq] | |
(if (empty? a-seq) #{#{}} | |
(let [hd (first a-seq) | |
tl (rest a-seq) | |
ptl (set-powerset tl)] | |
(clojure.set/union ptl (map #(conj % hd) ptl))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment