Strong and weak primes: Difference between revisions

m
→‎{{header|Perl 6}}: Style tweaks, DRY
m (→‎{{header|Pascal}}: changed indifferent into balanced)
m (→‎{{header|Perl 6}}: Style tweaks, DRY)
Line 460:
my @primes = $sieve.primes(10_000_019);
 
my (@weak, @balanced, @strong);
 
for 1 ..^ @primes - 1 -> $p {
given (@primes[$p - 1] + @primes[$p + 1]) / 2 {
when * > @primes[$p] { @weak.push: @primes[$p] }
when * < @primes[$p] { @strong.push: @primes[$p] }
default { @balanced.push: @primes[$p] }
}
}
 
for @strong, 'strong', 36, 1e6, 1e7,
@weak, 'weak', 37, 1e6, 1e7,
@balanced, 'balanced', 28, 1e6, 1e7
-> @pr, $type, $d, $c1, $c2 {
say "\nFirst $d $type primes:\n", @pr[^$d]».&comma;
say "Count of $type primes <= {comma $c11e6}: ", comma +@pr[^(@pr.first: * > $c11e6,:k)];
say "Count of $type primes <= {comma $c21e7}: ", comma +@pr;
}</lang>
{{out}}
10,343

edits