source code for "files/pe/pe_005.pl"
return to portfolio
- #!/usr/bin/perl
- use strict;
- use warnings;
- sub prime_sieve {
- my ($n, $i, $j) = (shift, 0, 0);
- my @sieve = (2, 3);
- $n = $n > 3 ? int $n : 3;
- for ($i=6; $i < $n; $i+= 6) {
- push(@sieve, $i-1, $i+1);
- }
- for $i (0..int @sieve-1) {
- for $j ($i+1..int @sieve-1) {
- if ($sieve[$j] % $sieve[$i] == 0) {
- $sieve[$j] = 1;
- }
- }
- }
- return @sieve;
- }
- # INCOMPLETE.... JUST DID THIS BY HAND, BECAUSE...