The PRIME NUMBERS - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QbasicNews.Com (http://qbasicnews.com/newforum/forum-3.html) +--- Forum: Challenges (http://qbasicnews.com/newforum/forum-10.html) +--- Thread: The PRIME NUMBERS (/thread-779.html) |
And the Russians beat the French. - Agamemnus - 06-02-2003 Code: CLS The PRIME NUMBERS - toonski84 - 06-02-2003 Well, i've always thought french kissing is better than regular kissing, so the possibility's certainly there... But then again, American cheese kicks ass, what with Wisconsin and all so I can't really say now. Re: And the Russians beat the French. - Mango - 06-03-2003 Nice job Agamemnus!! I learned a bunch from your optimization of my code...Here's what I see from a quick look goto faster than do:loop putting an array element into a variable then calling that variable is faster than calling the array element repetedly a^.5 is faster than squ(a) any others that I missed? Thanks again for the optimization. The PRIME NUMBERS - Antoni Gual - 06-03-2003 Agamemnus: You should review your code, some of the numbers printed end in 5 so they can't be primes... The PRIME NUMBERS - Agamemnus - 06-03-2003 Actually, SQR(x) is 2x faster than ^.5. I think that's because ^x uses a general method, and SQR(x) is a streamlined version of ^x, with a lot of things canceling out. Your code is slower because: 1) You have a while loop for your timer 2) You use UNTIL instead of direct IFs... Of course a good compiler will make ^.5 into SQR(x). But qb45.exe isn't actually that smart.. EDIT: You're right, I fouled up. EDIT: Fixed... The PRIME NUMBERS - whitetiger0990 - 06-03-2003 I like my program that finds primes up to the number specified Code: CLS The PRIME NUMBERS - Antoni Gual - 06-03-2003 Let's try it in the spanish way: The best way to calculate a square root is not calculating it at all.. No divisions or MOD either.. It calculates 16384 primes in 3 seconds in my P4 1,4... to display them it takes a little longer. Code: CLS The PRIME NUMBERS - Agamemnus - 06-03-2003 i'm lost. Toonski - Mango - 06-03-2003 Quote:this works well enough for me. I hope you don't think I picking on you...your code pegs 25, 49, and 121 as prime...all have prime roots, but they themselves are not prime...I hope this isn't good enough for you!!! :-? The PRIME NUMBERS - toonski84 - 06-03-2003 the world aint perfect.... hey, for pulling it out of me arse it worked okay, right? |