Sorry I didn't see your post, but still I win!!! >_< (it's sooo...
close!)

Academics can't beat game writers when it comes to speed!!!

On Nov 12, 11:01 pm, ram <[EMAIL PROTECTED]> wrote:
> Sorry, My mistake, that function has to be like this. But the results
> are decreased.
>
> 524752 primes founds in 10 seconds Highest Prime is :7761499
>
>         double sr = Math.Sqrt(Num);
>         foreach(int n in primes)
>         {
>             if (n > sr)
>                 return true;
>             if (Num % n == 0)
>                 return false;
>         }
>         return true;
>
> if there is a direct method to find the max index of list, where
> number is less than the sqrt of that number, results would have been
> better. here writing 2 if conditions taking time.
>
> On Nov 12, 11:12 pm, CK <[EMAIL PROTECTED]> wrote:
>
> > I'm not too sure about this line....
>
> >  if (n > Math.Sqrt(n))
> >                return true;
>
> > On 12 Nov, 10:22, ram <[EMAIL PROTECTED]> wrote:
>
> > > With the below configuration i got       7746653 primes founds in 10
> > > seconds   Highest Prime is :15493305
>
> > > CPU: Intel Pentiun E2140@ Dual 1.60GHZ
> > > RAM: 2GB
> > > OS: Windows 2003 Server
> > > .Net: 2.0
>
> > >     I used different logic. because suppose to decide a number whether
> > > it is prime number or not, we no need to check all the numbers below
> > > the square root of that number. IF we check all the primes of  below
> > > the square root of that number, its enough. because except 1 , atleast
> > > 1 factor of non-primary number must be a primary number. using this
> > > principle, we can find quicker than checking all numbers under the
> > > sqrt of the number.
>
> > >    List<int> primes = new List<int>();
> > >    protected void Page_Load(object sender, EventArgs e)
> > >    {
> > >        int seconds = 10;
> > >        primes.Add(2);
> > >        primes.Add(3);
> > >        primes[1] = 3;
> > >        DateTime x, y = DateTime.Now;
> > >        int a = 4, b = 2;
> > >        do
> > >        {
> > >            if (IsPrim(a))
> > >            {
> > >                primes.Add(a);
> > >                b++;
> > >            }
> > >            a++;
> > >            x = DateTime.Now;
> > >        } while ((x - y).TotalSeconds < seconds);
> > >              Response.Write(b.ToString() + " primes founds in " +
> > > seconds+ " seconds");
> > >        Response.Write("Highest Prime is :" + primes[primes.Count -
> > > 1].ToString());
> > >    }
>
> > >    private bool IsPrim(int Num)
> > >    {
> > >               foreach(int n in primes)
> > >        {
> > >            if (Num % n == 0)
> > >                return false;
> > >            if (n > Math.Sqrt(n))
> > >                return true;
> > >        }
> > >        return true;
> > >    }
>
> > > On Nov 11, 2:10 pm, CK <[EMAIL PROTECTED]> wrote:
>
> > > > This is something I've been working on for a while, and I thought it
> > > > might be fun to push it out to the group to see if anyone can better
> > > > my efforts.
>
> > > > The challange is to write a Windows Console App that generates prime
> > > > numbers.  It does not need to generate them in any specific order,
> > > > record them, or even catch all primes.  The aim is to calculate as
> > > > many unique primes as possible in 10 seconds.
>
> > > > Obviously, this will depend on the processor it runs on, so that will
> > > > be taken into account.
>
> > > > Once you have a solution, please post your results like the following:
> > > > (this is example data only)
>
> > > > CPU: Intel E6300
> > > > Cores: 2
> > > > RAM: 1GB
> > > > OS: Vista Home Premium
> > > > .Net: 3.5
> > > > Number of primes in 10 seconds: 10,000
> > > > Highest Prime found: 123247
>
> > > > To confirm your code is working properly, please post some large
> > > > primes (~100000) your code has found to verify that it is working
> > > > correctly.
>
> > > > Please also be willing to share your code.
>
> > > > Please enter, just for fun, and enjoy :)
>
> > > > PS. A Prime is a number that is only divisible by itself and 1.  1 is
> > > > not a prime, 2 is, 3 is, 4 isn't, 5 is etc.

Reply via email to