Created
April 21, 2013 06:27
-
-
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.
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
; 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)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"Execution timed out." in the fourth test case. I don't know why...