Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Prime list

by danaj (Friar)
on Feb 12, 2015 at 17:19 UTC ( [id://1116528]=note: print w/replies, xml ) Need Help??


in reply to Re: Prime list
in thread Prime list

I would suggest actually looking at a sieve, for example the ones on RosettaCode. They are much faster than the trial division method you link to, albeit generating primes starting at two.

For doing trial division, the skip-2-3 primality test from RosettaCode is twice as fast as the code you link to. Just wrap in something like: my @primes = grep { isprime($_) }  1..1000000;

While the regex solution mentioned in another reply is super clever, it is also super not useful for the task once past toy sizes.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-18 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found