In general, this function will work for non-integer collections. I
make no performance/laziness guarantees.
(defn selections-dups [coll n]
(let [r (range (count coll))
f #(< (last %1) (first %1))
s (remove f (selections r n))]
(map #(map (fn [x] (nth coll x)) %1) s)))
--~--
Ok, I'm an idiot. All I needed was (remove #(< (last %1) (first %1))
(selections [1 2 3 4] 3))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegrou
I've written up a fast, iterative version of a "unique-selections"
function, consistent with the approach taken in the other
combinatorics functions.
http://paste.lisp.org/display/74710
I haven't benchmarked it, but I would expect this version to be the
fastest of the alternatives mentioned here
On Sun, Feb 1, 2009 at 8:25 PM, Mark Engelberg wrote:
> (set (map sort (selections [1 2 3 4 5] 3)))
or
(distinct (map sort (selections [1 2 3 4 5] 3)))
if you want to generate the values lazily rather than all at once.
--~--~-~--~~~---~--~~
You received this mess
I'm not sure exactly what you want to remove, but it sounds like you
might be looking for something like:
(set (map sort (selections [1 2 3 4 5] 3)))
or:
(for [i (range 1 6) j (range i 6) k (range j 6)] [i j k])
On Sun, Feb 1, 2009 at 8:12 PM, kyle smith wrote:
>
> The selections function in
The selections function in combinatorics returns more than what I
need. (selections [ 1 2 3 4 5] 3) will return both (1 2 3) and (3 2
1), etc. However, I still need (1 1 1) (2 2 2), etc. I've tried
several times to write a function to filter out the 'duplicates', but
haven't quite got it.
--~--