[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A question about the implement the Integer Partitions
- From: Wim Couwenberg <wim.couwenberg@...>
- Date: Tue, 29 Dec 2009 15:21:32 +0100
Not sure what you want to do exactly. The following code prints all partitions.
Bye,
Wim
local function p(set, N, max)
if N == 0 then
print(unpack(set))
else
for i = max < N and max or N, 1, -1 do
set[#set + 1] = i
p(set, N - i, i)
set[#set] = nil
end
end
end
function partitions(n)
p({}, n, n)
end
partitions(tonumber(...))