62 lines
1.4 KiB
Plaintext
62 lines
1.4 KiB
Plaintext
// Rosetta Code problem: http://rosettacode.org/wiki/Aliquot_sequence_classifications
|
|
// by Galileo, 05/2022
|
|
|
|
sub sumFactors(n)
|
|
local i, s
|
|
|
|
for i = 1 to n / 2
|
|
if not mod(n, i) s = s + i
|
|
next
|
|
return s
|
|
end sub
|
|
|
|
sub printSeries(arr(), size, ty$)
|
|
local i
|
|
|
|
print "Integer: ", arr(0), ", Type: ", ty$, ", Series: ";
|
|
for i=0 to size-2
|
|
print arr(i), " ";
|
|
next i
|
|
print
|
|
end sub
|
|
|
|
sub alliquot(n)
|
|
local arr(16), i, j, ty$
|
|
|
|
ty$ = "Sociable"
|
|
arr(0) = n
|
|
|
|
for i = 1 to 15
|
|
arr(i) = sumFactors(arr(i-1))
|
|
if arr(i)=0 or arr(i)=n or (arr(i) = arr(i-1) and arr(i)<>n) then
|
|
if arr(i) = 0 then
|
|
ty$ = "Terminating"
|
|
elsif arr(i) = n and i = 1 then
|
|
ty$ = "Perfect"
|
|
elsif arr(i) = n and i = 2 then
|
|
ty$ = "Amicable"
|
|
elsif arr(i) = arr(i-1) and arr(i)<>n then
|
|
ty$ = "Aspiring"
|
|
end if
|
|
printSeries(arr(),i+1,ty$)
|
|
return
|
|
end if
|
|
for j = 1 to i-1
|
|
if arr(j) = arr(i) then
|
|
printSeries(arr(),i+1,"Cyclic")
|
|
return
|
|
end if
|
|
next j
|
|
next i
|
|
printSeries(arr(),i+1,"Non-Terminating")
|
|
end sub
|
|
|
|
data 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 28, 496, 220, 1184
|
|
data 12496, 1264460, 790, 909, 562, 1064, 1488, 0
|
|
|
|
do
|
|
read n
|
|
if not n break
|
|
alliquot(n)
|
|
loop
|