Anyway, your problem is that you remove the prime itself from @n. Don't do that.
my $max = shift || 100; my @nums = (2 .. $max); my @primes; while (@nums) { my $prime = shift @nums; push @primes, $prime; if ($prime ** 2 > $max) { push @primes, @nums; last; } @nums = grep {$_ % $prime != 0} @nums; } say "@primes";
In reply to Re: What am I missing?
by JavaFan
in thread What am I missing?
by neo_
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |