A similar version:

(defn combinations [[x & xs]]
    (if xs
        (for [e x c (combinations xs)]
            (cons e c))
        (map list x)))

Juan Manuel


El lunes 27 de febrero de 2012 15:23:30 UTC+1, Bill Caputo escribió:
>
> Here's a version that uses destructuring (but is otherwise the same) that 
> cleans it up a bit:
> (defn combinations [[x & xs]]
>      (if xs
>          (for [frstitems x tlitm (combinations xs)]
>              (flatten (list frstitems tlitm)))
>          x))
>
> On Feb 26, 2012, at 9:45 PM, Mike Ledoux wrote:
>
> > (defn combinations [items]
> >         (if (== (count items) 1)
> >             (flatten items)
> >             (for [frstitems (flatten (first items))
> >                   tlitm (combinations (rest items))]
> >                   (flatten (list frstitems tlitm)))))
>
>

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