MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Need Help with Sow within While Loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124892] Need Help with Sow within While Loop
  • From: KenR <ramsey2879 at msn.com>
  • Date: Sat, 11 Feb 2012 06:35:09 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

My Code is short so I will include it for reference
Caa = 1049001;
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++]]
First I noted that this loop took about one hour to find 31 Primes in
the above range.  This code appears to pick only primes but it only
picks about 34% of the primes. I am trying to find a false hit but out
of some 30,000 hits in the range from 3 up to 1050000 none were
composite numbers.  I would like to know if the code could be spead
up.  Also, how can I avoid reaping a list within a list such as {null,
{{a,b,c...}}} when I want {a,b,c...}.



  • Prev by Date: Re: Set page width for Put; or is there a stream associated with Put
  • Next by Date: Re: Input cells destroy Grids?
  • Previous by thread: Re: Set page width for Put; or is there a stream associated with Put
  • Next by thread: Need help with prime Test