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