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]
(concat
(map (fn [a b] (concat a (map #(conj % x) b)))
(cons nil ssbc) ssbc)
[[#{}]]))
[[#{}]] s))

(a tough one)

2 comments:

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 (http://paste.lisp.org/display/68832#1), 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).