[Haskell-cafe] Re: List algorithm
Christian Maeder
maeder at tzi.de
Tue May 22 09:06:44 EDT 2007
Henning Thielemann schrieb:
> On Mon, 21 May 2007, Steffen Mazanek wrote:
>
>> is there an efficient algorithm that takes two positive numbers n and m and
>> that computes all lists l of numbers 0<x<=n such that sum l = m?
>>
>> For instance
>> alg 5 1 = [[1]]
>> alg 5 2 = [[1,1],[2]]
>> alg 5 3 = [[1,1,1],[1,2],[2,1],[3]]
>> ...
>
> http://darcs.haskell.org/htam/src/Combinatorics/Partitions.hs
>
> alg = flip partitionsDec
*Combinatorics.Partitions> partitionsDec 5 3
[[3],[2,1],[1,1,1]]
so [1,2] is missing. And for these partitions I've also the attached module.
*Partition> parts 3
[3,2 1,1 1 1]
Christian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Partition.hs
Type: text/x-haskell
Size: 1232 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070522/c14e370d/Partition.bin
More information about the Haskell-Cafe
mailing list