Clojure Golf: subsets-by-card
(defn subsets-by-card [s]
(reduce (fn [ssbc x]
(concat
(map (fn [a b] (concat a (map #(conj % x) b)))
(cons nil ssbc) ssbc)
[[#{}]]))
[[#{}]] s))
(a tough one)
very neat! i’ll try to keep that shift-and-map trick in mind.
in the mean time, i came up with these variants on mine (http://paste.lisp.org/display/68832#1), but i think i stil prefer yours.
Yours is nice too. I tried to use iterate too but I hadn’t been able to come up with a solution which doesn’t use set or distinct to remove duplicates. Btw (clojure.set/difference a b) can also be written (apply disj a b).