Aliquot sequence classifications: Difference between revisions

Content added Content deleted
(→‎{{header|Haskell}}: Add Fortran)
(→‎{{header|Fortran}}: Minor afterthoughts.)
Line 110: Line 110:


=={{header|Fortran}}==
=={{header|Fortran}}==
This is straightforward for Fortran compilers that allow 64-bit integers, as with INTEGER*8.
This is straightforward for Fortran compilers that allow 64-bit integers, as with INTEGER*8 - though one must have faith in the correct functioning of the computer for such large numbers....


Output:
Output:
Line 140: Line 140:


Allowing more rope leads 1488 to overflow after the 83'rd value. Extending TOOBIG to 2**48 produces overflow from step 88, and the monster test value manages one more step.
Allowing more rope leads 1488 to overflow after the 83'rd value. Extending TOOBIG to 2**48 produces overflow from step 88, and the monster test value manages one more step.
Because the task involves inly a few numbers to test, there is not so much advantage to be gained by pre-calculating a set of sums of proper divisors.
Because the task involves only a few numbers to test, there is not so much advantage to be gained by pre-calculating a set of sums of proper divisors, but it does mean that no special tests are needed for N = 1 in function SUMF.


A more flexible syntax (such as Algol's) would enable the double scan of the TRAIL array to be avoided, as in if TRAIL[I:=MinLoc(Abs(TRAIL(1:L) - SF))] = SF then... That is, find the first index of array TRAIL such that ABS(TRAIL(1:L) - SF) is minimal, save that index in I, then access that element of TRAIL and test if it is equal to SF. Alternatively, use an explicit DO-loop to search for equality, thus not employing fancy syntax.
A more flexible syntax (such as Algol's) would enable the double scan of the TRAIL array to be avoided, as in if TRAIL[I:=MinLoc(Abs(TRAIL(1:L) - SF))] = SF then... That is, find the first index of array TRAIL such that ABS(TRAIL(1:L) - SF) is minimal, save that index in I, then access that element of TRAIL and test if it is equal to SF. The INDEX function could be use to find the first match, except that it is defined only for character variables. Alternatively, use an explicit DO-loop to search for equality, thus not employing fancy syntax, and not having to wonder if the ANY function will stop on the first match rather than wastefully continue the testing for all array elements. The modern style in manual writing is to employ vaguely general talk about arrays and omit specific details.


<lang Fortran>
<lang Fortran>
Line 262: Line 262:
INTEGER*8 I,N !Steppers.
INTEGER*8 I,N !Steppers.
INTEGER*8 THIS(14) !A testing collection.
INTEGER*8 THIS(14) !A testing collection.
DATA THIS/11,12,28,496,220,1184,12496,1264460,790,909,
DATA THIS/11,12,28,496,220,1184,12496,1264460,790,909, !Old-style continuation character in column six.
1 562,1064,1488,15355717786080/ !Monster value far exceeds the INTEGER*4 limit
1 562,1064,1488,15355717786080/ !Monster value far exceeds the INTEGER*4 limit


CALL PREPARESUMF !Values for every N up to the search limit will be called for at least once.
CALL PREPARESUMF !Prepare for 1:LOTS, even though this test run will use only a few.


DO I = 1,10 !As specified, the first ten integers.
DO I = 1,10 !As specified, the first ten integers.