Jump to content

Aliquot sequence classifications: Difference between revisions

(added output for 15355717786080)
Line 697:
{1488, Non-terminating, {1488, 2480, 3472, 4464, 8432, 9424, 10416, 21328, 22320, 55056, 95728, 96720, 236592, 459792, 881392, 882384, 1474608}}
{15355717786080, Non-terminating, {15355717786080, 44534663601120, 144940087464480, 471714103310688, 1130798979186912, 2688948041357088, 6050151708497568, 13613157922639968, 35513546724070632, 74727605255142168, 162658586225561832, 353930992506879768, 642678347124409032, 1125102611548462968, 1977286128289819992, 3415126495450394808, 7156435369823219592}}</pre>
 
=={{header|Oforth}}==
 
<lang oforth>Integer method: properDivs
{
| sqrtn i |
ListBuffer new dup add(1)
2 self nsqrt dup ->sqrtn for: i [
self i mod ifFalse: [ i over add self i / over add ]
]
self sqrtn sq == ifTrue: [ dup removeLast drop ]
sort
}
 
: aliquot(n) // ( n -- aList ) : Returns aliquot sequence of n
{
| end l |
2 47 pow ->end
ListBuffer new dup add(n) dup ->l
while (l size 16 < l last 0 <> and l last end <= and) [ l last properDivs sum l add ]
}
 
: aliquotClass(n) // ( n -- aList aString ) : Returns aliquot sequence and classification
{
| l i j |
n aliquot dup ->l
l last 0 == ifTrue: [ "terminate" return ]
l second n == ifTrue: [ "perfect" return ]
l third n == ifTrue: [ "amicable" return ]
l indexOfFrom(n, 2) ifNotNull: [ "sociable" return ]
 
l size loop: i [
l indexOfFrom(l at(i), i 1 +) -> j
j i 1 + == ifTrue: [ "aspiring" return ]
j ifNotNull: [ "cyclic" return ]
]
"non-terminating"
}</lang>
 
{{out}}
<pre>
>#[ dup . aliquotClass . ":" . println ] 10 seqEach
1 terminate : [1, 0]
2 terminate : [2, 1, 0]
3 terminate : [3, 1, 0]
4 terminate : [4, 3, 1, 0]
5 terminate : [5, 1, 0]
6 perfect : [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
7 terminate : [7, 1, 0]
8 terminate : [8, 7, 1, 0]
9 terminate : [9, 4, 3, 1, 0]
10 terminate : [10, 8, 7, 1, 0]
ok
</pre>
 
<pre>
>[ 11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488, 15355717786080 ] apply(#[ dup . aliquotClass . ":" . println ])
11 terminate : [11, 1, 0]
12 terminate : [12, 16, 15, 9, 4, 3, 1, 0]
28 perfect : [28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28]
496 perfect : [496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496]
220 amicable : [220, 284, 220, 284, 220, 284, 220, 284, 220, 284, 220, 284, 220, 284, 220, 284]
1184 amicable : [1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210]
12496 sociable : [12496, 14288, 15472, 14536, 14264, 12496, 14288, 15472, 14536, 14264, 12496, 14288, 15472, 14536, 14264, 12496]
1264460 sociable : [1264460, 1547860, 1727636, 1305184, 1264460, 1547860, 1727636, 1305184, 1264460, 1547860, 1727636, 1305184, 1264460, 1547860, 1727636, 1305184]
790 aspiring : [790, 650, 652, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, 496]
909 aspiring : [909, 417, 143, 25, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
562 cyclic : [562, 284, 220, 284, 220, 284, 220, 284, 220, 284, 220, 284, 220, 284, 220, 284]
1064 cyclic : [1064, 1336, 1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210, 1184, 1210]
1488 non-terminating : [1488, 2480, 3472, 4464, 8432, 9424, 10416, 21328, 22320, 55056, 95728, 96720, 236592, 459792, 881392, 882384]
15355717786080 non-terminating : [15355717786080, 44534663601120, 144940087464480]
ok
>
</pre>
 
=={{header|Perl}}==
1,015

edits

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