Last active
January 20, 2019 21:52
-
-
Save dogbert17/1c4e58b0350cbea3b4d3266b00b1cee8 to your computer and use it in GitHub Desktop.
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
use v6; | |
my int $max = 2_000_000; | |
# find all primes up to $max using The Sieve of Erathostenes | |
my int @a = (0..$max); | |
for (2..($max div 2)) -> int $i { | |
my int $j = 2; | |
@a[$i * $j++] = 1 while $i * $j <= $max; | |
} | |
# remove discarded numbers and store the rest in a set for ease of lookup | |
my @primes = @a.grep(-> int $num {$num > 1}); | |
my $result = @primes.sum; | |
say now - INIT now; | |
#my $x = now - INIT now; | |
#say $x; | |
#exit 42 if $x > 4.2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment