RosettaCodeData/Task/Aliquot-sequence-classifications/EasyLang/aliquot-sequence-classifications.easy

50 lines
1.2 KiB
Text
Raw Permalink Normal View History

2023-10-02 18:11:16 -07:00
fastfunc sumprop num .
2025-06-11 20:16:52 -04:00
if num = 1 : return 0
2023-10-02 18:11:16 -07:00
sum = 1
root = sqrt num
i = 2
while i < root
if num mod i = 0
sum += i + num / i
.
i += 1
.
if num mod root = 0
sum += root
.
return sum
.
func$ class k .
oldk = k
newk = sumprop oldk
oldk = newk
seq[] &= newk
2025-06-11 20:16:52 -04:00
if newk = 0 : return "terminating " & seq[]
if newk = k : return "perfect " & seq[]
2023-10-02 18:11:16 -07:00
newk = sumprop oldk
oldk = newk
seq[] &= newk
2025-06-11 20:16:52 -04:00
if newk = 0 : return "terminating " & seq[]
if newk = k : return "amicable " & seq[]
2023-10-02 18:11:16 -07:00
for t = 4 to 16
newk = sumprop oldk
seq[] &= newk
2025-06-11 20:16:52 -04:00
if newk = 0 : return "terminating " & seq[]
if newk = k : return "sociable (period " & t - 1 & ") " & seq[]
if newk = oldk : return "aspiring " & seq[]
2023-10-02 18:11:16 -07:00
for i to len seq[] - 1
2025-06-11 20:16:52 -04:00
if newk = seq[i] : return "cyclic (at " & newk & ") " & seq[]
2023-10-02 18:11:16 -07:00
.
2025-06-11 20:16:52 -04:00
if newk > 140737488355328 : return "non-terminating (term > 140737488355328) " & seq[]
2023-10-02 18:11:16 -07:00
oldk = newk
.
2025-06-11 20:16:52 -04:00
return "non-terminating (after 16 terms) " & seq[]
2023-10-02 18:11:16 -07:00
.
print "Number classification sequence"
for j = 1 to 12
2025-06-11 20:16:52 -04:00
print j & ": " & class j
2023-10-02 18:11:16 -07:00
.
for j in [ 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080 ]
2025-06-11 20:16:52 -04:00
print j & ": " & class j
2023-10-02 18:11:16 -07:00
.