Partition function P: Difference between revisions

Added J implementation
m (→‎{{header|FreeBASIC}}: fix then integer version and added then big number version)
(Added J implementation)
Line 573:
P(6666) = 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863
elapsed time: 59 milliseconds
</pre>
 
=={{header|J}}==
Solution stolen [https://code.jsoftware.com/wiki/Essays/Partitions#The_Number_of_Partitions verbatim from the J Wiki]. Note the use of memoization (M.) for efficiency:
 
<lang j> pn =: -/@(+/)@:($:"0)@rec ` (x:@(0&=)) @. (0>:]) M.
rec=: - (-: (*"1) _1 1 +/ 3 * ]) @ (>:@i.@>.@%:@((2%3)&*))</lang>
 
{{out}}
<pre> pn 6666
193655306161707661080005073394486091998480950338405932486880600467114423441282418165863
</pre>
 
Line 613 ⟶ 624:
<pre>p(6666) = 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863
0.260310 seconds (3.58 M allocations: 77.974 MiB, 8.54% gc time)</pre>
 
 
=={{header|Maple}}==
Anonymous user