Anonymous user
Aliquot sequence classifications: Difference between revisions
→{{header|REXX}}: simplified some statements, optimized the DO loop in the CLASSIFY subroutine, add/changed comments and whitespace.
(→{{header|Wren}}: Now uses Wren-math module.) |
(→{{header|REXX}}: simplified some statements, optimized the DO loop in the CLASSIFY subroutine, add/changed comments and whitespace.) |
||
Line 2,932:
Both of the above limitations are imposed by this Rosetta Code task's restriction requirements: ''For the purposes of this task, ···''.
<lang rexx>/*REXX program classifies various positive integers for types of aliquot sequences. */
parse arg low high $L
high= word(high low 10,1);
if $L='' then
numeric digits 100 /*be able to compute the number: BIG */
big= 2**47; NTlimit= 16 + 1 /*limits 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
end /*n*/
say
say center('first numbers for each classification', 79, "═")
class.=
do q=1 until class.sociable\==0
call classify -q
_= what;
end /*q*/ /* [↑] only display the 1st occurrence*/
say /* [↑] process until all classes found*/
say center('classifications for specific numbers', 79, "═")
do i=1 for words($L)
call classify word($L, i)
end /*i*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
classify: parse arg a 1 aa; a= abs(a)
$= s
c.= 0
c.s= 1
if $==a then
else do t=1 while s>0
m= s
parse var
$= $
if
if c.s then if m>0 then do; what= 'cyclic' ; leave; end
c.s= 1 /*assign another possible cyclic number*/
/* [↓] Rosetta Code task's limit: >16 */
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
sigma: procedure expose #. !.; parse arg x; if
s=
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 + j
#.x= s
return s /*return " "
{{out|output|text= when using the default input:}}
<pre>
|