On Sep 2, 4:48 pm, ax2groin <ax2gr...@gmail.com> wrote:
> That's what I get for posting a question while feeding a 1-year-old
> child and getting ready to leave for lunch.
>
> I was trying to put together a (for) construct to output the
> combinations of a set, and my logic was flawed.
>
> Here's what I really wanted [for sets of 3]:
>
> (for [m x n x o x :while (and (not= m n) (not= m o) (not= n o))] [m n
> o])
>
> Maybe not the most efficient, but the smallest construct I've come up
> with, but it isn't generic enough for me yet.
>
> I'll keep working on it.

So, you want to make sure each value in the vector is unique?  My
first thought was to put them into a set, then see if the set was
equal to the vector, but clojure's equality doesn't allow for that.
And if you put the set back into a vector, you've changed the order.

Now I think you might be asking for the permutations.
clojure.contrib.combinatorics as a permutations function:

user=> (clojure.contrib.combinatorics/permutations [1 2 3])
((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to