Skip to content

Instantly share code, notes, and snippets.

@jizhang
Created April 21, 2013 06:27
Show Gist options
  • Save jizhang/5428687 to your computer and use it in GitHub Desktop.
Save jizhang/5428687 to your computer and use it in GitHub Desktop.
Write a function which generates the power set of a given set. The power set of a set x is the set of all subsets of x, including the empty set and x itself.
; 4clojure.com - 85. Power Set
; http://www.4clojure.com/problem/85
(fn [s]
(set (for [i (range 0 (apply * (repeat (count s) 2)))]
(set (for [index-base (range 0 (count s))
:let [index (apply * (repeat index-base 2))]
:when (pos? (bit-and i index))]
(nth (seq s) index-base))))))
@jizhang
Copy link
Author

jizhang commented Apr 21, 2013

"Execution timed out." in the fourth test case. I don't know why...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment