Created
May 3, 2017 10:44
-
-
Save Timbus/2965b4f3c5ff29c165b56a13f2fbc668 to your computer and use it in GitHub Desktop.
*In angry Megatron voice*: PRIME!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub primes-sieve3(Int $max) { | |
my int @sieve; | |
my int $effective-max = ($max-1) div 2; | |
lazy gather for 1 .. $effective-max -> int $i { | |
FIRST take 2; | |
next if @sieve[$i]; | |
my int $prime = 2 * $i + 1; | |
take $prime; | |
my $fill-range = ($effective-max - $i) div $prime; | |
for 1 .. $fill-range -> int $j { | |
@sieve[$prime * $j + $i] = 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment