[Haskell-cafe] List algorithm

Mark T.B. Carroll Mark.Carroll at Aetion.com
Mon May 21 15:51:44 EDT 2007


"Steffen Mazanek" <haskell at steffen-mazanek.de> writes:

> alg 5 1 = [[1]]
> alg 5 2 = [[1,1],[2]]
> alg 5 3 = [[1,1,1],[1,2],[2,1],[3]]

Would this be better?

alg n m =
    case signum m of
      -1 -> []
      0 -> [[]]
      1 -> [ x : xs | x <- [1..n], xs <- alg n (m - x) ]

-- Mark



More information about the Haskell-Cafe mailing list