Left factorials: Difference between revisions

Content added Content deleted
(add RPL)
Line 3,242: Line 3,242:


=={{header|RPL}}==
=={{header|RPL}}==
For small values of n, we can use the native format for integers:
For small values of n, the built-in number type can support the job:
≪ '''IF''' DUP '''THEN''' 0 1 ROT 1 - '''FOR''' k k FACT + '''NEXT END''' ≫ ‘<span style="color:blue">LFACT</span>’ STO
≪ '''IF''' DUP '''THEN''' 0 1 ROT 1 - '''FOR''' k k FACT + '''NEXT END''' ≫ ‘<span style="color:blue">LFACT</span>’ STO
Line 3,249: Line 3,249:
'''Output:'''
'''Output:'''
1: { 0 1 2 4 10 34 154 874 5914 46234 409114 }
1: { 0 1 2 4 10 34 154 874 5914 46234 409114 }
For 20 through 110 (inclusive) by tens, we need a kind of BigInt library if using a RPL version of the previous century. <code>ADDbig</code> and <code>MULbig</code> are defined at [[Long multiplication#RPL|Long multiplication]].
For 20 through 110 (inclusive) by tens, we need a kind of BigInt library if using a RPL version from the previous century. <code>ADDbig</code> and <code>MULbig</code> are defined at [[Long multiplication#RPL|Long multiplication]].
Calculation is optimized by using the recursive formula: <code>!(n+1) = !n * n + 1</code>
Calculation is optimized by using the recursive formula: <code>!(n+1) = !n * n + 1</code>
≪ "1" SWAP
≪ "1" SWAP
'''WHILE''' DUP 1 > '''REPEAT'''
'''WHILE''' DUP 1 > '''REPEAT'''
1 - DUP →STR <span style="color:blue">ROTMULbig</span> "1" <span style="color:blue"><span style="color:blue">ADDbig</span></span> SWAP
1 - DUP →STR ROT <span style="color:blue">MULbig</span> "1" <span style="color:blue"><span style="color:blue">ADDbig</span></span> SWAP
'''END''' DROP
'''END''' DROP
≫ ‘<span style="color:blue">LFACTbig</span>’ STO
≫ ‘<span style="color:blue">LFACTbig</span>’ STO