Aliquot sequence classifications: Difference between revisions

no edit summary
(Added PowerShell)
No edit summary
Line 2,099:
</pre>
The loop to calculate 15355717786080 takes forever (literally)
 
=={{header|ZX Spectrum Basic}}==
{{trans|AWK}}
This program is correct. However, a bug in the ROM of the ZX Spectrum makes the number 909 of an erroneous result. However, the same program running on Sam BASIC (a superset of Sinclair BASIC that ran on the computer Sam Coupé) provides the correct results.
<lang zxbasic>10 PRINT "Number classification sequence"
20 INPUT "Enter a number (0 to end): ";k: IF k>0 THEN GO SUB 2000: PRINT k;" ";s$: GO TO 20
40 STOP
1000 REM sumprop
1010 IF oldk=1 THEN LET newk=0: RETURN
1020 LET sum=1
1030 LET root=SQR oldk
1040 FOR i=2 TO root-0.1
1050 IF oldk/i=INT (oldk/i) THEN LET sum=sum+i+oldk/i
1060 NEXT i
1070 IF oldk/root=INT (oldk/root) THEN LET sum=sum+root
1080 LET newk=sum
1090 RETURN
2000 REM class
2010 LET oldk=k: LET s$=" "
2020 GO SUB 1000
2030 LET oldk=newk
2040 LET s$=s$+" "+STR$ newk
2050 IF newk=0 THEN LET s$="terminating"+s$: RETURN
2060 IF newk=k THEN LET s$="perfect"+s$: RETURN
2070 GO SUB 1000
2080 LET oldk=newk
2090 LET s$=s$+" "+STR$ newk
2100 IF newk=0 THEN LET s$="terminating"+s$: RETURN
2110 IF newk=k THEN LET s$="amicable"+s$: RETURN
2120 FOR t=4 TO 16
2130 GO SUB 1000
2140 LET s$=s$+" "+STR$ newk
2150 IF newk=0 THEN LET s$="terminating"+s$: RETURN
2160 IF newk=k THEN LET s$="sociable (period "+STR$ (t-1)+")"+s$: RETURN
2170 IF newk=oldk THEN LET s$="aspiring"+s$: RETURN
2180 LET b$=" "+STR$ newk+" ": LET ls=LEN s$: LET lb=LEN b$: LET ls=ls-lb
2190 FOR i=1 TO ls
2200 IF s$(i TO i+lb-1)=b$ THEN LET s$="cyclic (at "+STR$ newk+") "+s$: LET i=ls
2210 NEXT i
2220 IF LEN s$<>(ls+lb) THEN RETURN
2300 IF newk>140737488355328 THEN LET s$="non-terminating (term > 140737488355328)"+s$: RETURN
2310 LET oldk=newk
2320 NEXT t
2330 LET s$="non-terminating (after 16 terms)"+s$
2340 RETURN</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</pre>
672

edits