Power set: Difference between revisions

Content added Content deleted
m (Typo)
Line 433: Line 433:


'''Alternate solution''', with no dependency on third-party library:
'''Alternate solution''', with no dependency on third-party library:
<lang Clojure>(defn powerset
<lang Clojure>(defn powerset [coll]
(reduce (fn [a x]
[coll]
(reduce (fn [a x] (->> a (map #(set (concat #{x} %))) (concat a) set))
(->> a
(map #(set (concat #{x} %)))
(concat a)
set))
#{#{}} coll))
#{#{}} coll))