note
kudra
Much worse than the previous offering and just plain bad
approaches (what can I say--I'm bad at golf and I wanted
to play with using an array. [id://20633|look here] if
you want to see some shorter solutions):
<p>
<code>
# 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)
}
</code>
152.
<p>
<code>
# 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"
}
</code>
104.
<p>
Too bad we're not playing basketball. <!-- I wrote the
104 one then the 152 one. -->
<p>
<strong>Update</strong>
<code>
# Example of use: @result = sieve(60);
sub sieve{
L:for(2..pop){for my $b(2..$_-1){next L if($_%$b<1)}push@_,$_}@_
}
</code>
65. Does not mark of multiples but tests each number
(only as far as needed, at least), so not really allowed.
81695
81695