Skip to content

Instantly share code, notes, and snippets.

@JJ
Created July 31, 2020 15:57
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 JJ/2c7f92a7de0729337c89f497ccf3758d to your computer and use it in GitHub Desktop.
Save JJ/2c7f92a7de0729337c89f497ccf3758d to your computer and use it in GitHub Desktop.
Using threads to compute primes in an interval
#!/usr/bin/env raku
constant $interval = 100000;
my @threads = (^10).map: -> $i {
Thread.start(
name => "Checking primes from {$i * $interval } to { ($i+1)*$interval}",
sub {
for ($i * $interval)..^(($i+1)*$interval) -> $n {
next if ( $n %% 2 ) | ( $n %% 3 ) | ($n %% 5 );
say "Prime $n found in $*THREAD" if $n.is-prime;
}
},
);
}
.finish for @threads;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment