Sylvester's sequence: Difference between revisions
Content added Content deleted
(Added Prolog solution) |
(→{{header|ALGOL 68}}: Corrected spelling of reciprocal - thanks to Gerard Schildberger for showing me the error of my ways...) |
||
Line 25: | Line 25: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} |
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} |
||
Uses Algol 68G's LONG LONG INT and LONG LONG REAL which have specifiable precision. The sum of the |
Uses Algol 68G's LONG LONG INT and LONG LONG REAL which have specifiable precision. The sum of the reciprocals in the output has been manually edited to replace a large number of nines with ... to reduce the width. |
||
<lang algol68>BEGIN # calculate elements of Sylvestor's Sequence # |
<lang algol68>BEGIN # calculate elements of Sylvestor's Sequence # |
||
PR precision 200 PR # set the number of digits for LONG LONG modes # |
PR precision 200 PR # set the number of digits for LONG LONG modes # |
||
Line 44: | Line 44: | ||
# find the first 10 elements of Sylvestor's Seuence # |
# find the first 10 elements of Sylvestor's Seuence # |
||
[]LONG LONG INT seq = SYLVESTOR 10; |
[]LONG LONG INT seq = SYLVESTOR 10; |
||
# show the sequence and sum the |
# show the sequence and sum the reciprocals # |
||
LONG LONG REAL |
LONG LONG REAL reciprocal sum := 0; |
||
FOR i FROM LWB seq TO UPB seq DO |
FOR i FROM LWB seq TO UPB seq DO |
||
print( ( whole( seq[ i ], 0 ), newline ) ); |
print( ( whole( seq[ i ], 0 ), newline ) ); |
||
reciprocal sum +:= 1 / seq[ i ] |
|||
OD; |
OD; |
||
print( ( "Sum of |
print( ( "Sum of reciprocals: ", reciprocal sum, newline ) ) |
||
END |
END |
||
</lang> |
</lang> |
||
Line 65: | Line 65: | ||
12864938683278671740537145998360961546653259485195807 |
12864938683278671740537145998360961546653259485195807 |
||
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443 |
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443 |
||
Sum of |
Sum of reciprocals: +9.99999999999999999999999999999999999999999...999999999999999999999999999964e -1 |
||
</pre> |
</pre> |
||