Re: Question about this little method I wrote

2012-03-18 Thread Mike Ledoux
Thank you everybody who responded to my question! It is appreciated. On Feb 29, 3:14 pm, JuanManuel Gimeno Illa wrote: > A similar version: > > (defn combinations [[x & xs]] >     (if xs >         (for [e x c (combinations xs)] >             (cons e c)) >         (map list x))) > > Juan Manuel >

Re: Question about this little method I wrote

2012-02-29 Thread JuanManuel Gimeno Illa
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 s

Re: Question about this little method I wrote

2012-02-29 Thread Steve Miner
There's contrib library that you might find interesting: https://github.com/clojure/math.combinatorics -- 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

Re: Question about this little method I wrote

2012-02-29 Thread Nicolas Duchenne
Hi Mike, If I understood your aim correctly, and if you accept changing the output of (combinations [[1 2]]) to ((1) (2)) instead of (1 2), which I think makes more sense,then the reduce function does the job in one line for you. (defn combinations [items] (reduce #(for [l % i %2] (conj l i)) [

Re: Question about this little method I wrote

2012-02-27 Thread Bill Caputo
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:

Question about this little method I wrote

2012-02-27 Thread Mike Ledoux
So I recently decided to start learning Clojure. I installed Clojure box and wrote this little method to compute all possible combinations of input: (defn combinations [items] (if (== (count items) 1) (flatten items) (for [frstitems (flatten (first items))