Re: [Haskell-cafe] Combination-lock problem

2004-08-12 Thread Fritz Ruehr
Well, as far as that goes, we can shave off a little bit (around 7%) this way: combs = mapM (\k-[0..k]) (As a bonus, it's even a bit more cryptic/symbolic, in the fine tradition of APL one-liner character-shavings.) But who's counting? :) :) :) -- Fritz Ruehr On Aug 11, 2004, at 3:22 PM,

Re: [Haskell-cafe] Combination-lock problem

2004-08-12 Thread Lyle Kopnicky
Even shorter: c=mapM(\k-[0..k]) - Lyle Fritz Ruehr wrote: Well, as far as that goes, we can shave off a little bit (around 7%) this way: combs = mapM (\k-[0..k]) (As a bonus, it's even a bit more cryptic/symbolic, in the fine tradition of APL one-liner character-shavings.) But who's

Re: [Haskell-cafe] Combination-lock problem

2004-08-11 Thread Henning Thielemann
On Wed, 11 Aug 2004, Lyle Kopnicky wrote: Here's my version: combs [] = [] combs [n] = [[i] | i - [0..n]] combs (n:r) = let combsr = combs r in [i:cr | i - [0..n], cr - combsr] Since there is one zero combination, it should be combs [] = [[]] Then you can also remove the definition of

Re: [Haskell-cafe] Combination-lock problem

2004-08-11 Thread Cale Gibbard
Oops, just realised that I didn't include the mailing list in my original reply to Florian -- here was my reply: - Hi, I would write it as one of the following, keys [] = [[]] keys (x:xs) = [0..x] = (\k - map (k:) (keys xs)) -- or, keys' [] = [[]] keys' (x:xs) = do { k - [0..x] ;

Re: [Haskell-cafe] Combination-lock problem

2004-08-11 Thread Lyle Kopnicky
Henning Thielemann wrote: On Wed, 11 Aug 2004, Lyle Kopnicky wrote: Here's my version: combs [] = [] combs [n] = [[i] | i - [0..n]] combs (n:r) = let combsr = combs r in [i:cr | i - [0..n], cr - combsr] Since there is one zero combination, it should be combs [] = [[]] Ah, yes. I

Re: [Haskell-cafe] Combination-lock problem

2004-08-11 Thread Mike Gunter
Why so long-winded :-)? combs = mapM (enumFromTo 0) mike Lyle Kopnicky [EMAIL PROTECTED] writes: ... Here is the improved version: combs [] = [[]] combs (n:r) = [i:cr | i - [0..n], cr - combs r] ... ___ Haskell-Cafe mailing list [EMAIL

Re: [Haskell-cafe] Combination-lock problem

2004-08-10 Thread Graham Klyne
At 06:01 10/08/04 +0200, Florian Boehl wrote: Hi, I'ld like to generate a list (of lists) that contains all combinations of natural numbers stored in another list. It should work like a combination-lock. E.g.: [2,2] - [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] If I know the length 'l'

Re: [Haskell-cafe] Combination-lock problem

2004-08-10 Thread ajb
G'day all. At 06:01 10/08/04 +0200, Florian Boehl wrote: If I know the length 'l' of the 'locklist', I can solve the problem via generators. E.g.: l = 2: [[a,b] | a - [0..locklist!!0], b - [0..locklist!!1]] But if the length is unknown (because it's dynamic) this solutions (of course) fails.

Re: [Haskell-cafe] Combination-lock problem

2004-08-09 Thread Thomas L. Bevan
Just make the function recursive. There is a simple relation between, l [a,b,c] and l [b,c] Tom On Tue, 10 Aug 2004 14:01, Florian Boehl wrote: Hi, I'ld like to generate a list (of lists) that contains all combinations of natural numbers stored in another list. It should work like a