Skip to content

Instantly share code, notes, and snippets.

Created October 25, 2011 23:45
Show Gist options
  • Save anonymous/1314821 to your computer and use it in GitHub Desktop.
Save anonymous/1314821 to your computer and use it in GitHub Desktop.
;; fronx's solution to Power Set
;; https://4clojure.com/problem/85
(fn [s]
(let [bit-filter (fn [items mask]
(set
(keep-indexed
(fn [idx item]
(if (bit-test mask idx)
item))
items)))]
(-> (set
(for [mask (range 0 (Math/pow 2 (count s)))]
(bit-filter s mask)))
(concat #{s})
set)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment