05-29-2003, 10:16 PM
[quote="Touf"]NOBODY has reach your level for the moment !/quote]
I just looked at the code I wrote earlier...and tweaked it a bit. This one is about 75% faster. The difference is I moved a squareroot out of a loop, and I got rid of a comparison and a goto.
I just looked at the code I wrote earlier...and tweaked it a bit. This one is about 75% faster. The difference is I moved a squareroot out of a loop, and I got rid of a comparison and a goto.
Code:
DEFINT A-Z 'Joe Campbell-2003
DIM smallprimes(1 TO 3500) AS INTEGER 'array holds forst 3500 prime numbers
CLS
PRINT "This program finds primes, then prints the highest found, 1 per second"
a = 0
max = 3
smallprimes(1) = 3
next1 = 5
count = 1
DO WHILE count < 3500
sqroot = SQR(next1)
DO
a = a + 1
IF next1 MOD smallprimes(a) = 0 THEN GOTO notprime
LOOP WHILE sqroot > smallprimes(a)
count = count + 1
smallprimes(count) = next1
notprime:
next1 = next1 + 2
a = 0
LOOP
nextbig& = next1 - 2
over:
t& = TIMER
t1& = t& + 1
DO
sqroot = SQR(nextbig&)
DO
a = a + 1
IF sqroot < smallprimes(a) THEN
APrime& = nextbig&
EXIT DO
END IF
LOOP WHILE nextbig& MOD smallprimes(a)
nextbig& = nextbig& + 2
a = 0
LOOP UNTIL TIMER > t1&
LOCATE 2
PRINT APrime&
GOTO over