neo_ has asked for the wisdom of the Perl Monks concerning the following question:
Pretty good! Wait...it is cutting out the 2 and 3. And if I go higher:#!/usr/bin/perl print "Show primes up to: "; chomp($max = <>); @n = (2..$max); @f = (2..sqrt(@n)); foreach $i (@f) { @e = grep {$_ % $i != 0} @n; @n = (); @n = @e; } print "@n\n"; ./sieve.pl Show primes up to: 21 5 7 11 13 17 19
That's no good. Can someone help show me what i'm missing? Not looking for an answer, just looking for a shove in the right direction. Any help is appreciated../sieve.pl Show primes up to: 31 7 11 13 17 19 23 29 31
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What am I missing?
by moritz (Cardinal) on Aug 11, 2009 at 06:41 UTC | |
Re: What am I missing?
by Anonymous Monk on Aug 11, 2009 at 02:07 UTC | |
by neo_ (Novice) on Aug 11, 2009 at 02:17 UTC | |
Re: What am I missing?
by JavaFan (Canon) on Aug 11, 2009 at 12:48 UTC | |
by neo_ (Novice) on Aug 11, 2009 at 16:22 UTC | |
Re: What am I missing?
by psini (Deacon) on Aug 11, 2009 at 04:13 UTC | |
by jwkrahn (Abbot) on Aug 11, 2009 at 06:17 UTC |