Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Eratosthenes Sieve

by IraTarball (Monk)
on Oct 22, 2001 at 20:54 UTC ( [id://120584]=note: print w/replies, xml ) Need Help??


in reply to Eratosthenes Sieve

Not to be a pain in the ass, but I noticed yours always gives the seed number as the last element of the list. I thought the method only gave the seed number if it was prime. I took a look at the link you have above and it seems to confirm this. I made your <'s into <='s and it works like The Others.

sub Eratosthenes_Sieve($){ for(@a=(1)x($_[0]+1),$p=2; $p**2<=$_[0];){for($j=2*$p ;$j<=$_[0];$j+=$p){$a[$j]= 0}for($a[++$p]){}}grep {$a [$_]}(2..$#a)}

Ira,

"So... What do all these little arrows mean?"
~unknown

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found