Thread: New Code View Single Post
 2011-09-02, 03:31 #8 LaurV Romulan Interpreter     Jun 2011 Thailand 927510 Posts Code:  begin N:=Primes[200]+3; /// for testing Not 0 1223 {you better do postincrement of it} a1 := GetTickCount; //timer repeat j:=0; {here preincrement works better, to exit the loop when is found} repeat J:=J+1; until (J>200) or not Is_Div(N-Primes[j]); {not 20, as in your program} N:=N+2; until N>20000; {not 1000!} a1 := GetTickCount-a1; {printing stuff} end; I think you just wanna start flame wars. Your program is bullshit, and I believe you just typed it in some "random" fashion, and you never ran it in a computer, first of all because "comments" (in all Pascal versions I know) are given between braces {} and not by // like in C-style. Beside of the fact that your program is full of shit variables you never use (did you claim you can actually.... optimize any program???), it only checked 1001 even numbers between 1226 and 3226, and for each of these numbers only tried if it can be written as a sum of two primes "a+b", with "a" being one of the first 20 primes. Please see my comment in red. That is, the 20th prime is 71. Your program was checking if an even number in the interval 1226..3226 (in Pascal notation) can be written as a sum of a prime smaller then 72 and another prime. That's all. You could check that much easier and faster in Pascal using "set" operators (Pascal can do a lot of stuff with sets of objects). See how much time do you need if you give the right values for limits, like I modified above in your code, and anyhow this won't be enough correct to verify Goldbach, if you want to go to N=200000 then you have to store the primes to 100000, just in case you run in some number which is a sum of two primes of about the same size (try playing on some superior limit of a very large prime gap). But for the solely purpose of timing, you should use the right number of iterations.... Tip: If you just copy the codesnap from above, be careful how you set the compiler's behaviour of evaluating boolean expressions, otherwise you could get an "array out of bounds" when you evaluate Primes[201] for j=201 at the most inner loop. Last fiddled with by LaurV on 2011-09-02 at 03:43