Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2011 05:58
Show Gist options
  • Save anonymous/796299 to your computer and use it in GitHub Desktop.
Save anonymous/796299 to your computer and use it in GitHub Desktop.
get powerset of set
(use '[clojure.set]
'[clojure.test])
(defn powerset [ls]
(if (empty? ls) '(())
(union (powerset (next ls))
(map #(conj % (first ls)) (powerset (next ls))))))
(deftest test-powerset
(is (= '(()) (powerset '())))
(is (= '((1) ()) (powerset '(1))))
(is (= '((1) (1 2) (2) ()) (powerset '(1 2)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment