BigEd wrote:
Silly me, this is surely the best way:
22 X=2-X : C = C + X
It's not so easy (in Basic) to see how to extend this idea to cover multiples of 5 in an efficient way, if GOTO is expensive.
Yesterday evening I didn't find my mistake implementing this. (I forgot to change FOR C=5... into FOR C=3....
)
So now skipping 3 in both loops now looks like:
Code:
10 ZS=5: INPUT A,B
16 X=0
20 FORC=3TOASTEP2
22 X=2-X:C=C+X
25 Y=0
30 FOR D = 3 TO SQR(C) STEP 2
35 Y=2-Y:D=D+Y
40 IF INT(C/D)*D = C THEN 80
50 NEXT D
60 IF C-ZS >= B THEN PRINT C,ZS,C-ZS, : GOTO 100
70 ZS = C
80 NEXT C
90 PRINT " KEINE LOESUNG ";
100 PRINT
110 GOTO 10
Yes, this should result in a small speed improvement. I gave it a try, here is what has happened:
Code:
MS-Basic V1.1 on SYM (1MHz)
3 sorted out (IF..GOTO).....: A: 41,4 (100%) B: 67,4 (100%) C: 785,4 (100%) D: 1991,1 (100%) E: 3663,7 (100%)
BigEds \3 outer loop only...: A: 40,7 ( 98%) B: 66,5 ( 99%) C: 778,5 ( 99%) D: 1967,9 ( 99%) E: ____,_ ( %)
BigEds \3 outer & inner loop: A: 42,1 (102%) B: 68,7 (102%) C: 810,6 (103%) D: 2061,7 (103%) E: ____,_ ( %)
EhBasic V2.22 on a 2 MHz 6502
3 sorted out (IF..GOTO).....: A: 11,3 (100%) B: 19,1 (100%) C: 252,8 (100%) D: 664,1 (100%) E: 1261,1 (100%)
BigEds \3 outer loop only...: A: 11,0 ( 97%) B: 18,4 ( 96%) C: 251,0 ( 99%) D: 662,4 (100%) E: 1260,0 (100%)
BigEds \3 outer & inner loop: A: 12,6 (112%) B: 20,4 (107%) C: 273,4 (108%) D: 720,0 (108%) E: 1373,0 (109%)
surprising
Cheers,
Arne
EDITs: some late results pasted