On 22 May 2010, at 20:38, Kasim wrote:

> Hi folks,
> 
> I am just asking you guy's input to following:
> 
> (defn- k-filter [el coll]
>  (filter #(not (= el %)) coll))
> 
> (defn combinations [n coll]
>  (if (= n 0)
>    nil
>    (for [el coll nlis (combinations (- n 1) (k-filter el coll))]
>      [el nlis])))
> 
> It is not working now. Here is an example I want this code to produce:
> (combinations 2 '[A B C] -> ([AB],[AC],[BC]). Above code uses
> recursion and I would like to see not recursive version. Any one care
> to enlighten me? Thanks in advance.


Check out the clojure.contrib.combinatorics/combinations function:

  
http://richhickey.github.com/clojure-contrib/combinatorics-api.html#clojure.contrib.combinatorics/combinations

-Steve

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