Jump to content

Aliquot sequence classifications: Difference between revisions

(Aliquot sequence classifications in QBasic)
Line 5,733:
15355717786080: Non-terminating [15355717786080, 44534663601120, 144940087464480]
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<lang Yabasic>// 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</lang>
{{out}}
<pre>Integer: 1, Type: Terminating, Series: 1
Integer: 2, Type: Terminating, Series: 2 1
Integer: 3, Type: Terminating, Series: 3 1
Integer: 4, Type: Terminating, Series: 4 3 1
Integer: 5, Type: Terminating, Series: 5 1
Integer: 6, Type: Perfect, Series: 6
Integer: 7, Type: Terminating, Series: 7 1
Integer: 8, Type: Terminating, Series: 8 7 1
Integer: 9, Type: Terminating, Series: 9 4 3 1
Integer: 10, Type: Terminating, Series: 10 8 7 1
Integer: 11, Type: Terminating, Series: 11 1
Integer: 12, Type: Terminating, Series: 12 16 15 9 4 3 1
Integer: 28, Type: Perfect, Series: 28
Integer: 496, Type: Perfect, Series: 496
Integer: 220, Type: Amicable, Series: 220 284
Integer: 1184, Type: Amicable, Series: 1184 1210
Integer: 12496, Type: Sociable, Series: 12496 14288 15472 14536 14264
Integer: 1264460, Type: Sociable, Series: 1264460 1547860 1727636 1305184
Integer: 790, Type: Aspiring, Series: 790 650 652 496
Integer: 909, Type: Aspiring, Series: 909 417 143 25 6
Integer: 562, Type: Cyclic, Series: 562 284 220
Integer: 1064, Type: Cyclic, Series: 1064 1336 1184 1210
Integer: 1488, Type: Non-Terminating, Series: 1488 2480 3472 4464 8432 9424 10416 21328 22320 55056 95728 96720 236592 459792 881392 882384
---Program done, press RETURN---</pre>
 
=={{header|zkl}}==
672

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.