Partition function P: Difference between revisions

Added a Lingo version
m (→‎{{header|Haskell}}: Applied Ormolu)
(Added a Lingo version)
Line 860:
<pre>p(6666) = 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863
0.260310 seconds (3.58 M allocations: 77.974 MiB, 8.54% gc time)</pre>
 
=={{header|Lingo}}==
Lingo natively only supports 32 bit integers, so P(6666) would be way too big.
<lang lingo>-- 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
i = 1
param = 1
res = 0
repeat while TRUE
if (i - 1) 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 + 1)/2
else
param = param + i + 1
end if
if param > n then exit repeat
i = i + 1
end repeat
res_table[n] = res
return res
end</lang>
{{out}}
<pre>
ms = _system.milliseconds
put "P(121):", partitions(121)
put "Time (ms):", _system.milliseconds - ms
-- P(121): 2056148051
-- Time (ms): 5
</pre>
 
=={{header|Maple}}==
Anonymous user