Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Math help: Finding Prime Numbers

by CountZero (Bishop)
on Nov 12, 2006 at 20:32 UTC ( [id://583589]=note: print w/replies, xml ) Need Help??


in reply to Math help: Finding Prime Numbers

It is said that for finding primes less than 10,000,000,000 the Sieve of Eratosthenes cannot be beat for speed.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^2: Math help: Finding Prime Numbers
by Anonymous Monk on Nov 13, 2006 at 10:07 UTC
    Considering that lists of prime numbers are easily available, I'm not so sure whether a sieve beats reading them from disk.

    Unless one is doing it for fun, as an exercise, to check the validity of the list, or to expand a list, there's no reason to write a program that generates prime numbers starting from 2. We promote people to reuse code and not reinvent the wheel. There's no reason to be different when it comes to data.

      I'm not so sure whether a sieve beats reading them from disk

      Yep - a half-decent sieve does beat reading from disk ... unless it's a very short list that you're after.

      Cheers,
      Rob
      Update: Actually ... come to think about it ... a half-decent sieve might beat reading from disk, even if it is a very short list

        Ovid said:

        This is part of a larger set of code which is intended to be pure Perl, ...

        Can you write a "half descent sieve" in Perl?

        Also, how about if you want the 2e6 through 3e6 primes the first time you call and the 1e6 through 2e6 the second time?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://583589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-20 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found