[Haskell-cafe] Building all possible element combinations from N lists.

2012-10-25 Thread dokondr
Hi all, I am looking for the algorithm and code better then the one I wrote (please see below) to solve the problem given in the subject. Unfortunately I finally need to implement this algorithm in Java. That's why I am not only interested in beautiful Haskell algorithms, but also in the one that I

Re: [Haskell-cafe] Building all possible element combinations from N lists.

2012-10-25 Thread Alex Stangl
On Fri, Oct 26, 2012 at 12:44:31AM +0400, dokondr wrote: > I am looking for the algorithm and code better then the one I wrote (please > Build all possible element combinations from N lists. > Valid combination consists of k <= N elements. > Where each element of a single combination is taken from

Re: [Haskell-cafe] Building all possible element combinations from N lists.

2012-10-25 Thread dokondr
On Fri, Oct 26, 2012 Alex Stangl wrote: >* * > combos [] = [[]] > combos ([]:ls) = combos ls > combos ((h:t):ls) = map (h:) (combos ls) ++ combos (t:ls) > Excellent, thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/m

Re: [Haskell-cafe] Building all possible element combinations from N lists.

2012-10-25 Thread Jake McArthur
I golfed a bit. :) sequence <=< filterM (const [False ..]) On Thu, Oct 25, 2012 at 6:11 PM, dokondr wrote: > > On Fri, Oct 26, 2012 Alex Stangl wrote: > >> >> combos [] = [[]] >> combos ([]:ls) = combos ls >> combos ((h:t):ls) = map (h:) (combos ls) ++ combos (t:ls) >> > > Excellent, thanks!

Re: [Haskell-cafe] Building all possible element combinations from N lists.

2012-10-25 Thread Alex Stangl
On Thu, Oct 25, 2012 at 06:34:53PM -0400, Jake McArthur wrote: > I golfed a bit. :) > > sequence <=< filterM (const [False ..]) I was thinking of golfing this myself tonight, but probably wouldn't have come up with this. Thanks for sparing me the effort. Bravo! Alex ___

Re: [Haskell-cafe] Building all possible element combinations from N lists.

2012-10-28 Thread dokondr
On Fri, Oct 26, 2012 at 2:34 AM, Jake McArthur wrote: > I golfed a bit. :) > > sequence <=< filterM (const [False ..]) > > What is "golfed" and "<=<" ? Please, explain. Thanks, Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://ww

Re: [Haskell-cafe] Building all possible element combinations from N lists.

2012-10-28 Thread Clark Gaebel
Golfed: http://en.wikipedia.org/wiki/Code_golf <=< : Also known as Kleisli composition. More info: http://www.haskell.org/hoogle/?hoogle=%3C%3D%3C On Sun, Oct 28, 2012 at 4:36 PM, dokondr wrote: > On Fri, Oct 26, 2012 at 2:34 AM, Jake McArthur wrote: > >> I golfed a bit. :) >> >> sequence <=