- #1
ramsey2879
- 841
- 3
I posted this in number theory "Ramsey Primes" but I don't think this qualifies as an improper use of this forum. I need help with my code. My code for Mathematical is short so I will include it below for reference. There are some flaws. For instance the Reap/Sow function generates a list of the form {Null,{{prime3,prime5,prime6,prime8,...}}}. I want to generate a simple list {prime3,prime5,prime6,prime8...}. Also, the code took about an hour to pick out 31 primes between 1049000 and 1050000. Overall, about 2/3 of the prime numbers are not picked out, but that is what I am looking for code that will generate only primes, not code that will generate all primes but also include some composites. So far some 30,000 prime numbers between 5 and 1050000 were generated with no false hits. Any help improving my code will be appreciated. The code follows:
Caa = 5
Reap[While[Caa < 1050001,
Co = 1;
S0 = 2;
S1 = 3;
While[Co < ((Caa-1)/2),Temp = Mod[6 S1 - S0 - 6,Caa];If[Temp <= 1,Break[]];
S0=S1;S1=Temp;Co++];
n = ((Caa-1)/2) - Co; If[n<2,If[n>0, Sow[Caa]]];
Caa++;Caa++]]
Caa = 5
Reap[While[Caa < 1050001,
Co = 1;
S0 = 2;
S1 = 3;
While[Co < ((Caa-1)/2),Temp = Mod[6 S1 - S0 - 6,Caa];If[Temp <= 1,Break[]];
S0=S1;S1=Temp;Co++];
n = ((Caa-1)/2) - Co; If[n<2,If[n>0, Sow[Caa]]];
Caa++;Caa++]]