Anonymous user
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
#.=.; #.0=0; #.1=0
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=
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
$=$ 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
end /*j*/ /* [↓] adjust for square. ___*/
if j*j==x then s=s +
#.x=s /*define
return s /*return " " " " " */</lang>
<pre>
════════════════════════════numbers from 1 to 10════════════════════════════
|