Clojure Golf: subsets-by-card

unsorted — cgrand, 20 October 2008 @ 23 h 09 min
(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 »

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

    Comment by achim — 21 October 2008 @ 18 h 53 min
  2. 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).

    Comment by Christophe Grand — 22 October 2008 @ 11 h 07 min

RSS feed for comments on this post. TrackBack URI

Leave a comment

(c) 2018 Clojure and me | powered by WordPress with Barecity