Aliquot sequence classifications: Difference between revisions

Content added Content deleted
(→‎{{header|Fortran}}: The new Mathematica example, with its N-precision arithmetic, confirms the third value for the monster. Via Fortran, crunching two steps of the sequence takes about a second.)
Line 30: Line 30:
* [[Amicable pairs]]
* [[Amicable pairs]]


=={{header|AWK}}==

<lang awk>
#!/bin/gawk -f
function sumprop(num, i,sum,root) {
if (num == 1) return 0
sum=1
root=sqrt(num)
for ( i=2; i < root; i++) {
if (num % i == 0 )
{
sum = sum + i + num/i
}
}
if (num % root == 0)
{
sum = sum + root
}
return sum
}
function class(k, oldk,newk,seq){
# first term
oldk = k
seq = " "
# second term
newk = sumprop(oldk)
oldk = newk
seq = seq " " newk
if (newk == 0) return "terminating " seq
if (newk == k) return "perfect " seq
# third term
newk = sumprop(oldk)
oldk = newk
seq = seq " " newk
if (newk == 0) return "terminating " seq
if (newk == k) return "amicable " seq
for (t=4; t<17; t++) {
newk = sumprop(oldk)
seq = seq " " newk
if (newk == 0) return "terminating " seq
if (newk == k) return "sociable (period " t-1 ") "seq
if (newk == oldk) return "aspiring " seq
if (index(seq," " newk " ") > 0) return "cyclic (at " newk ") " seq
if (newk > 140737488355328) return "non-terminating (term > 140737488355328) " seq
oldk = newk
}
return "non-terminating (after 16 terms) " seq
}
BEGIN{
print "Number classification sequence"
for (j=1; j < 11; j++)
{
print j,class(j)}
print 11,class(11)
print 12,class(12)
print 28,class(28)
print 496,class(496)
print 220,class(220)
print 1184,class(1184)
print 12496,class(12496)
print 1264460,class(1264460)
print 790,class(790)
print 909,class(909)
print 562,class(562)
print 1064,class(1064)
print 1488,class(1488)
print 15355717786080,class(15355717786080)
}

</lang>
{{out}}
<pre>
Number classification sequence
1 terminating 0
2 terminating 1 0
3 terminating 1 0
4 terminating 3 1 0
5 terminating 1 0
6 perfect 6
7 terminating 1 0
8 terminating 7 1 0
9 terminating 4 3 1 0
10 terminating 8 7 1 0
11 terminating 1 0
12 terminating 16 15 9 4 3 1 0
28 perfect 28
496 perfect 496
220 amicable 284 220
1184 amicable 1210 1184
12496 sociable (period 5) 14288 15472 14536 14264 12496
1264460 sociable (period 4) 1547860 1727636 1305184 1264460
790 aspiring 650 652 496 496
909 aspiring 417 143 25 6 6
562 cyclic (at 284) 284 220 284
1064 cyclic (at 1184) 1336 1184 1210 1184
1488 non-terminating (after 16 terms) 2480 3472 4464 8432 9424 10416 21328 22320 55056 95728 96720 236592 459792 881392 882384
1.53557e+13 non-terminating (term > 140737488355328) 4.45347e+13 1.4494e+14 4.71714e+14

</pre>
=={{header|D}}==
=={{header|D}}==
{{trans|Python}}
{{trans|Python}}