Partition function P: Difference between revisions
Content added Content deleted
m (→{{header|FreeBASIC}}: fix then integer version and added then big number version) |
(Added J implementation) |
||
Line 573: | Line 573: | ||
P(6666) = 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863 |
P(6666) = 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863 |
||
elapsed time: 59 milliseconds |
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> |
</pre> |
||
Line 613: | Line 624: | ||
<pre>p(6666) = 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863 |
<pre>p(6666) = 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863 |
||
0.260310 seconds (3.58 M allocations: 77.974 MiB, 8.54% gc time)</pre> |
0.260310 seconds (3.58 M allocations: 77.974 MiB, 8.54% gc time)</pre> |
||
=={{header|Maple}}== |
=={{header|Maple}}== |