Aliquot sequence classifications: Difference between revisions

Added 11l
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(Added 11l)
Line 31:
*   [[Amicable pairs]]
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>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))</lang>
 
{{out}}
<pre>
terminating: [1, 0]
terminating: [2, 1, 0]
terminating: [3, 1, 0]
terminating: [4, 3, 1, 0]
terminating: [5, 1, 0]
perfect: [6]
terminating: [7, 1, 0]
terminating: [8, 7, 1, 0]
terminating: [9, 4, 3, 1, 0]
terminating: [10, 8, 7, 1, 0]
 
terminating: [11, 1, 0]
terminating: [12, 16, 15, 9, 4, 3, 1, 0]
perfect: [28]
perfect: [496]
amicable: [220, 284]
amicable: [1184, 1210]
sociable of length 5: [12496, 14288, 15472, 14536, 14264]
sociable of length 4: [1264460, 1547860, 1727636, 1305184]
aspiring: [790, 650, 652, 496]
aspiring: [909, 417, 143, 25, 6]
cyclic back to 284: [562, 284, 220]
cyclic back to 1184: [1064, 1336, 1184, 1210]
non-terminating: [1488, 2480, 3472, 4464, 8432, 9424, 10416, 21328, 22320, 55056, 95728, 96720, 236592, 459792, 881392, 882384, 1474608]
</pre>
 
=={{header|ALGOL 68}}==
1,480

edits