Clojure and me has moved.

Monday, October 20, 2008

Clojure Golf: subsets-by-card

This post has moved, go to its new location
(defn subsets-by-card [s]
(reduce (fn [ssbc x]
(map (fn [a b] (concat a (map #(conj % x) b)))
(cons nil ssbc) ssbc)
[[#{}]] s))

(a tough one)


achim said...

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 (, but i think i stil prefer yours.

Christophe Grand said...

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).