38 lines
1 KiB
Text
38 lines
1 KiB
Text
F pdsum(n)
|
||
R sum((1 .. (n + 1) I/ 2).filter(x -> @n % x == 0 & @n != x))
|
||
|
||
F aliquot(n, maxlen = 16, maxterm = 2 ^ 30)
|
||
I n == 0
|
||
R (‘terminating’, [0])
|
||
V s = [n]
|
||
V slen = 1
|
||
V new = n
|
||
L slen <= maxlen & new < maxterm
|
||
new = pdsum(s.last)
|
||
I new C s
|
||
I s[0] == new
|
||
I slen == 1
|
||
R (‘perfect’, s)
|
||
E I slen == 2
|
||
R (‘amicable’, s)
|
||
E
|
||
R (‘sociable of length #.’.format(slen), s)
|
||
E I s.last == new
|
||
R (‘aspiring’, s)
|
||
E
|
||
R (‘cyclic back to #.’.format(new), s)
|
||
E I new == 0
|
||
R (‘terminating’, s [+] [0])
|
||
E
|
||
s.append(new)
|
||
slen++
|
||
L.was_no_break
|
||
R (‘non-terminating’, s)
|
||
|
||
L(n) 1..10
|
||
V (cls, seq) = aliquot(n)
|
||
print(‘#.: #.’.format(cls, seq))
|
||
print()
|
||
L(n) [11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488]
|
||
V (cls, seq) = aliquot(n)
|
||
print(‘#.: #.’.format(cls, seq))
|