Strong and weak primes: Difference between revisions
Content added Content deleted
m (→{{header|Pascal}}: changed indifferent into balanced) |
Thundergnat (talk | contribs) 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 |
for @strong, 'strong', 36, |
||
@weak, 'weak', 37 |
@weak, 'weak', 37, |
||
@balanced, 'balanced', 28 |
@balanced, 'balanced', 28 |
||
-> @pr, $type, $d |
-> @pr, $type, $d { |
||
say "\nFirst $d $type primes:\n", @pr[^$d]»., |
say "\nFirst $d $type primes:\n", @pr[^$d]»., |
||
say "Count of $type primes <= {comma |
say "Count of $type primes <= {comma 1e6}: ", comma +@pr[^(@pr.first: * > 1e6,:k)]; |
||
say "Count of $type primes <= {comma |
say "Count of $type primes <= {comma 1e7}: ", comma +@pr; |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |