On 23 Jun 2008, at 6:30 pm, leledumbo wrote:
I've successfully create a function to return lists of N-ple that satisfy the
following function:
x1 + x2 + x3 + ... + xN = C
But unfortunately, it's not generic.

Why do you want it to be a tuple? All the elements are the same type, so it
might as well be a list.

        part 0 c | c == 0 = [[]]
        part (n+1) c | c >= 0 = [(x:xs) | x <- [0..c],
                                          xs <- part n (c-x)]

(WARNING: UNTESTED CODE!)
Knuth TAOCP Volume 4 has some stuff on enumerating partitions.

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to