Aliquot sequence classifications: Difference between revisions

Line 389:
1488: non-terminating long sequence (1488 2480 3472 4464 8432 9424 10416 21328 22320 55056 95728 96720 236592 459792 881392 882384 1474608)
15355717786080: non-terminating big number (15355717786080 44534663601120 144940087464480)
</pre>
 
=={{header|zkl}}==
<lang zkl>fcn properDivs(n){ [1.. (n + 1)/2 + 1].filter('wrap(x){ n%x==0 and n!=x }) }
fcn aliquot(k){ //-->Walker
Walker(fcn(rk){ k:=rk.value; if(k)rk.set(properDivs(k).sum()); k }.fp(Ref(k)))
}(10).walk(15).println();
 
fcn classify(k){
const MAX=(2).pow(47);
ak,aks:=aliquot(k), ak.walk(16);
_,a2,a3:=aks;
if(a2==k) return("perfect");
if(a3==k) return("amicable");
aspiring:='wrap(){
foreach n in (aks.len()-1){ if(aks[n]==aks[n+1]) return(True) }
False
};
cyclic:='wrap(){
foreach n in (aks.len()-1){ if(aks[n+1,*].holds(aks[n])) return(aks[n]) }
False
};
(if(aks.filter1('==(0))!=False) "terminating"
else if(n:=aks[1,*].filter1n('==(k))) "sociable of length " + (n+1)
else if(aks.filter1('>(MAX))) "non-terminating"
else if(aspiring()) "aspiring"
else if((c:=cyclic())!=False) "cyclic on " + c
else "non-terminating" )
+ " " + aks.filter();
}</lang>
<lang zkl>[1..10].pump(fcn(k){ "%6d is %s".fmt(k,classify(k)).println() });
T(11,12,28,496,220,1184,12496,1264460,790,909,562,1064,1488)
.pump(fcn(k){ "%6d is %s".fmt(k,classify(k)).println() });</lang>
{{out}}
<pre>
L(10,8,7,1,0,0,0,0,0,0,0,0,0,0,0)
1 is terminating L(1)
2 is terminating L(2,1)
3 is terminating L(3,1)
4 is terminating L(4,3,1)
5 is terminating L(5,1)
6 is perfect
7 is terminating L(7,1)
8 is terminating L(8,7,1)
9 is terminating L(9,4,3,1)
10 is terminating L(10,8,7,1)
11 is terminating L(11,1)
12 is terminating L(12,16,15,9,4,3,1)
28 is perfect
496 is perfect
220 is amicable
1184 is amicable
12496 is sociable of length 5 L(12496,14288,15472,14536,14264,12496,14288,15472,14536,14264,12496,14288,15472,14536,14264,12496)
1264460 is sociable of length 4 L(1264460,1547860,1727636,1305184,1264460,1547860,1727636,1305184,1264460,1547860,1727636,1305184,1264460,1547860,1727636,1305184)
790 is aspiring L(790,650,652,496,496,496,496,496,496,496,496,496,496,496,496,496)
909 is aspiring L(909,417,143,25,6,6,6,6,6,6,6,6,6,6,6,6)
562 is cyclic on 284 L(562,284,220,284,220,284,220,284,220,284,220,284,220,284,220,284)
1064 is cyclic on 1184 L(1064,1336,1184,1210,1184,1210,1184,1210,1184,1210,1184,1210,1184,1210,1184,1210)
1488 is non-terminating L(1488,2480,3472,4464,8432,9424,10416,21328,22320,55056,95728,96720,236592,459792,881392,882384)
</pre>
Anonymous user