BBS: Inland Empire Archive Date: 10-18-92 (03:51) Number: 319 From: VICTOR YIU Refer#: NONE To: ERIC B. FORD Recvd: NO Subj: Re: Prime Number Generato Conf: (2) Quik_Bas
-=> Quoting Eric B. Ford to Victor Yiu <=- > Stats: On a 486/34 w/256K secondary cache: > Prime numbers up to 10000 in .3 seconds. :*Sorry -- but it was a typo -- it was .38. > Note: It was compiled under QB 4.5 and the numbers > are printed out using PRINT X;... I could not read it, so your version expanded: -------------clip DEFINT A-Z Last = 10000 DIM Prime(Last + 1) AS INTEGER H = Last \ 2 T! = TIMER FOR I = 3 TO H STEP 2 J = 2 WHILE J * I <= Last Prime(J * I) = 1 J = J + 1 WEND NEXT I FOR J = 4 TO Last STEP 4 Prime(J) = 1 NEXT J PRINT "2 3"; FOR I = 3 TO Last STEP 2 ' I opt.'d here: STEP 2 IF Prime(I) = 0 THEN PRINT I; NEXT I PRINT PRINT "Computed in"; TIMER - T!; "seconds" -------------end of clip I am very impressed -- I have not though of an algorithm similar to yours. My algorithm work its way up testing if it is... Yours makes a list of all the NON primes... Amazing -- why didn't I think of that? Now, down to the benchmarks. In the QB environment, it was about the same. But when I compiled it, mine kept on getting .38. But yours fluctuated from .29 to .34. Incredible! It's fast. Mine -- well -- it must be the "GUI" interface <G>. Incredible... I would like others to see if they could speed it up even more in QB... ... A clean desk is a sign of a cluttered desk drawer. --- Blue Wave/RA v2.10 [NR] * Origin: Hard Disc Cafe / Houston Texas / (713) 589-2690 / (1:106/30.0)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET