Skip to content

Instantly share code, notes, and snippets.

@robertpfeiffer
Created December 12, 2008 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertpfeiffer/35157 to your computer and use it in GitHub Desktop.
Save robertpfeiffer/35157 to your computer and use it in GitHub Desktop.
(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