Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Eratosthenes Sieve

by IraTarball (Monk)
on Oct 22, 2001 at 20:54 UTC ( #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
Node Status?
node history
Node Type: note [id://120584]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2019-06-19 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (87 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!