Aliquot sequence classifications: Difference between revisions

→‎{{header|Fortran}}: Minor afterthoughts.
(→‎{{header|Haskell}}: Add Fortran)
(→‎{{header|Fortran}}: Minor afterthoughts.)
Line 110:
 
=={{header|Fortran}}==
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:
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.
Because the task involves inlyonly 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. 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>
Line 262:
INTEGER*8 I,N !Steppers.
INTEGER*8 THIS(14) !A testing collection.
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
 
CALL PREPARESUMF !ValuesPrepare for every1:LOTS, Neven upthough tothis thetest search limitrun will beuse calledonly fora at least oncefew.
 
DO I = 1,10 !As specified, the first ten integers.
1,220

edits