Aliquot sequence classifications: Difference between revisions

m
→‎{{header|REXX}}: optimized the CLASSIDY subroutine (for speed), used a template for OUTPUT.
m (added commas to the 2**47 number.)
m (→‎{{header|REXX}}: optimized the CLASSIDY subroutine (for speed), used a template for OUTPUT.)
Line 2,044:
numeric digits 20 /*be able to handle the number: BIG */
big=2**47; NTlimit=16+1 /*limit for a non─terminating sequence.*/
numeric digits max(9, 1 + length(big)) ) /*be able to handle big numbers for // */
#.=.; #.0=0; #.1=0 /*#. are the proper divisor sums. */
say center('numbers from ' low " to " high, 79, "═")
do n=low to high; call classify n /*call a subroutine to classify number.*/
Line 2,072:
if $==a then what='perfect' /*check for a "perfect" number. */
else do t=1 while s\==0 /*loop until sum isn't 0 or > big.*/
m=word($,s words($)) /*obtain the last number in sequence. */
if #.m==. then s=sigma(m) /*Not defined? Then sum proper divisors*/
else s=#.m /*use the previously found integer. */
if m==s & m\==0 then do; what='aspiring' ; leave; end
ifparse var word($,2)==a . word2 . /* " " 2nd then do; " what='amicable' " ; " leave; end*/
$if word2==$a s then do; what='amicable' ; leave; /*append a sum to the integer sequence.*/end
$=$ s /*append a sum to the integer sequence.*/
if s==a & t>3 then do; what='sociable' ; leave; end
if c.s & m\==0 then do; what='cyclic' ; leave; end
Line 2,085 ⟶ 2,086:
if s>big then do; what='NON-TERMINATING'; leave; end
end /*t*/ /* [↑] only permit within reason. */
if aa>0 then say right(a, digits() ) 'is' center(what, 15) $
return /* [↑] only display if A is positive.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
sigma: procedure expose #.; parse arg x; if x<2 then return 0; odd=x//2
s=1 /* [↓] use only EVEN | ODD ints. ___*/
do j=2+odd by 1+odd while j*j<x /*divide by all the integers up to √ X */
if x//j==0 then s=s + j + x % j /*add the two divisors to the sum. */
end /*j*/ /* [↓] adjust for square. ___*/
if j*j==x then s=s +j j /*Was X a square? If so, add √ X */
#.x=s /*define divisondivision sum for argument X.*/
return s /*return " " " " " */</lang>
'''{{out|output''' |text=&nbsp; when using the default input:}}
<pre>
════════════════════════════numbers from 1 to 10════════════════════════════