lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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(...))