Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

(kudra: basketball) Re: (Golf): Sieve of Eratosthenes

by kudra (Vicar)
on May 19, 2001 at 15:44 UTC ( [id://81705]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # Example use: @result = sieve(60);
    sub sieve {
    my$m=pop;my@l=(0..$m);for(my$x=0;$x<$m;$x++){next if($l[$x]<2);my $i=2
    +;my$n=0;for(;$n<$m;$i++){$n=$x*$i;next if($n>$m);$l[$
    n]=0}}@l=grep{$l[$_]}(0..$m)
    }
    
  2. or download this
    # Example of use: sieve(60);
    
    sub sieve {
    my$m=pop;@_=(2..$m);for my $c(@_){my%b=map{$_,1}grep{($_%$c)==0}($c+1.
    +.$m);@_=grep{!$b{$_}}@_}die"@_\n"
    }
    
  3. or download this
    # Example of use: @result = sieve(60);
    
    ...
    L:for(2..pop){for my $b(2..$_-1){next L if($_%$b<1)}push@_,$_}@_
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://81705]
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: (3)
As of 2024-04-20 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found