HP Forums
(38G) Integer Partitions (Using Ramanujam's Method) - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (38G) Integer Partitions (Using Ramanujam's Method) (/thread-3532.html)



(38G) Integer Partitions (Using Ramanujam's Method) - Gerald H - 04-01-2015 01:12 PM

For input N a positive integer the programme returns the number of integer partitions in Ans & displays the result.

Faster than Gauss' method but subject to inaccuracies for higher values of N.

Improvements welcome.

INT(Ans)►N:
IF N<1
THEN
0:
ELSE
0►B:
√(2/3)►H:
1►C:
N-1/24►F:
√F►R:
R*H*π►G:
π*H/F►H:
F*R►F:
2*π►P:
2*N►Q:
DO
0►E:
FOR D=1 TO C STEP 1;
C►I:
D►J:
DO
I MOD J►K:
J►I:
K►J:
UNTIL
K==0
END:
IF I==1
THEN
COS(π*( Σ(I=1,C-1,(FRAC((D*I)/C)-.5)*(I/C-.5))+.25-(Q*D)/C))+E►E:
END:
END:
G/C:
(COSH(Ans)*H/C-SINH(Ans)/F)*√C/P►O:
C+1►C:
O*E+B►B:
UNTIL
ROUND(O+B,0)==ROUND(B,0)
END:
ROUND(B,0)►B:
END:
ERASE:
DISP 2;" p("N")":
DISP 4;" "B:
FREEZE: