Thanks, how could I miss checking the contrib library!  I was actually
trying to implement the combination logic that I did in Scala a while
back. Here is the scala code:

object Combination {
    def combine[T](n:Int,list:List[T]):List[List[T]]=
        n match {
            case 0 => List(List())
            case _ => for { elem <- list
                            nlist <- combine(n-1, list dropWhile (_!
=elem))
                            } yield elem::nlist
                }
}

Of course, this is with repetition allowed. The combinatorics contrib
library has non recursive implementation that I can
reference. However, I would like to see non recursive version of the
"permutations" Clojure code above.

Thanks,


On May 22, 8:55 pm, ka <[email protected]> wrote:
> As Steve said, better look at the combinatorics-api.
>
> As for your original code, the idea you have gives all permutations
> not combinations!  Few changes will make it functioning -
>
> (defn permutations [n coll]
>     (if (= n 1)
>       (map #(vector %) coll)
>       (for [el coll nlis (permutations (- n 1) (k-filter el coll))]
>         (conj nlis el))))
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

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

Reply via email to