29 lines
671 B
Plaintext
29 lines
671 B
Plaintext
-- returns number of partitions of n
|
|
on partitions(n, res_table)
|
|
if n < 2 then return 1
|
|
if voidP(res_table) then
|
|
res_table = []
|
|
res_table[n] = 0
|
|
else if res_table[n] then
|
|
return res_table[n]
|
|
end if
|
|
res = 0
|
|
i = 0
|
|
param = 1
|
|
repeat while param <= n
|
|
if i mod 4 < 2 then
|
|
res = res + partitions(n - param, res_table)
|
|
else
|
|
res = res - partitions(n - param, res_table)
|
|
end if
|
|
if i mod 2 then
|
|
param = param + i + 2
|
|
else
|
|
param = param + i / 2 + 1
|
|
end if
|
|
i = i + 1
|
|
end repeat
|
|
res_table[n] = res
|
|
return res
|
|
end
|