22 lines
763 B
Text
22 lines
763 B
Text
fcn classify(k){
|
|
const MAX=(2).pow(47); // 140737488355328
|
|
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();
|
|
}
|