Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDaniel/092458de72b918a2873c4429b427500a to your computer and use it in GitHub Desktop.
Save AlexDaniel/092458de72b918a2873c4429b427500a to your computer and use it in GitHub Desktop.
use v6;
my int $max = 2_000_000 × 4;
# 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;
my $x = now - INIT now;
say $x;
exit 42 if $x > 4.85;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment