Bernoulli numbers: Difference between revisions
Content added Content deleted
m (→HP-49+ version: typo) |
(→HP-49+ version: dramatically simplified) |
||
Line 3,978: | Line 3,978: | ||
===HP-49+ version=== |
===HP-49+ version=== |
||
Latest RPL implementations can natively handle long fractions and generate Bernoulli numbers. |
|||
{{works with|HP|49}} |
{{works with|HP|49}} |
||
≪ { } |
|||
1 ROT 1 + '''FOR''' m |
|||
m INV + |
|||
m 1 + → j |
|||
≪ '''WHILE''' 'j' DECR 2 ≥ '''REPEAT''' |
|||
j 1 - DUP2 GETI UNROT GET - |
|||
OVER * EVAL PUT |
|||
'''END''' |
|||
≫ |
|||
'''NEXT''' |
|||
HEAD |
|||
≫ '<span style="color:blue">BRNOU</span>' STO |
|||
≪ { } |
≪ { } |
||
0 ROT '''FOR''' n |
0 ROT '''FOR''' n |
||
'''IF''' n 2 > LASTARG MOD AND NOT '''THEN''' n |
'''IF''' n 2 > LASTARG MOD AND NOT '''THEN''' n IBERNOULLI + '''END''' |
||
'''NEXT''' |
'''NEXT''' |
||
≫ '<span style="color:blue">TASK</span>' STO |
≫ '<span style="color:blue">TASK</span>' STO |
||
Line 4,004: | Line 3,991: | ||
1: {1 -1/2 1/6 -1/30 1/42 -1/30 5/66 -691/2730 7/6 -3617/510 43867/798 -174611/330 854513/138 -236364091/2730 8553103/6 -23749461029/870 8615841276005/14322 -7709321041217/510 2577687858367/6 -26315271553053477373/1919190 2929993913841559/6 -261082718496449122051/13530 1520097643918070802691/1806 -27833269579301024235023/690 596451111593912163277961/282 -5609403368997817686249127547/46410 495057205241079648212477525/66 -801165718135489957347924991853/1590 9149963634884862421418123812691/798 -2479392929313226753685415739663229/870 84483613348880041862046775994036021/354 -1215233140483755572040304994079820246041491/56786730} |
1: {1 -1/2 1/6 -1/30 1/42 -1/30 5/66 -691/2730 7/6 -3617/510 43867/798 -174611/330 854513/138 -236364091/2730 8553103/6 -23749461029/870 8615841276005/14322 -7709321041217/510 2577687858367/6 -26315271553053477373/1919190 2929993913841559/6 -261082718496449122051/13530 1520097643918070802691/1806 -27833269579301024235023/690 596451111593912163277961/282 -5609403368997817686249127547/46410 495057205241079648212477525/66 -801165718135489957347924991853/1590 9149963634884862421418123812691/798 -2479392929313226753685415739663229/870 84483613348880041862046775994036021/354 -1215233140483755572040304994079820246041491/56786730} |
||
</pre> |
</pre> |
||
Runs in |
Runs in 3 minutes 40 on a HP-50g, against 1 hour and 30 minutes if calculating Bernoulli numbers with the above function. |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |