Strong and weak primes: Difference between revisions

Content added Content deleted
m (→‎{{header|Pascal}}: changed indifferent into balanced)
m (→‎{{header|Perl 6}}: Style tweaks, DRY)
Line 460: Line 460:
my @primes = $sieve.primes(10_000_019);
my @primes = $sieve.primes(10_000_019);


my (@weak,@balanced,@strong);
my (@weak, @balanced, @strong);


for 1 ..^ @primes - 1 -> $p {
for 1 ..^ @primes - 1 -> $p {
given (@primes[$p - 1] + @primes[$p + 1]) / 2 {
given (@primes[$p - 1] + @primes[$p + 1]) / 2 {
when * > @primes[$p] { @weak.push: @primes[$p] }
when * > @primes[$p] { @weak.push: @primes[$p] }
when * < @primes[$p] { @strong.push: @primes[$p] }
when * < @primes[$p] { @strong.push: @primes[$p] }
default { @balanced.push: @primes[$p] }
default { @balanced.push: @primes[$p] }
}
}
}
}


for @strong, 'strong', 36, 1e6, 1e7,
for @strong, 'strong', 36,
@weak, 'weak', 37, 1e6, 1e7,
@weak, 'weak', 37,
@balanced, 'balanced', 28, 1e6, 1e7
@balanced, 'balanced', 28
-> @pr, $type, $d, $c1, $c2 {
-> @pr, $type, $d {
say "\nFirst $d $type primes:\n", @pr[^$d]».&comma;
say "\nFirst $d $type primes:\n", @pr[^$d]».&comma;
say "Count of $type primes <= {comma $c1}: ", comma +@pr[^(@pr.first: * > $c1,:k)];
say "Count of $type primes <= {comma 1e6}: ", comma +@pr[^(@pr.first: * > 1e6,:k)];
say "Count of $type primes <= {comma $c2}: ", comma +@pr;
say "Count of $type primes <= {comma 1e7}: ", comma +@pr;
}</lang>
}</lang>
{{out}}
{{out}}