Pierpont primes: Difference between revisions

→‎{{header|Perl 6}}: Exposition and hard goal, still way less than a minute to complete
(→‎{{header|Perl 6}}: Exposition and hard goal, still way less than a minute to complete)
Line 168:
=={{header|Perl 6}}==
{{works with|Rakudo|2019.07.1}}
 
This finesse version never produces more Pierpont numbers than it needs to
fulfill the requested number of primes. It uses a series of parallel iterators
with additional iterators added as required. No need to speculatively generate
an overabundance. No need to rely on magic numbers. No need to sort them. It
produces exactly what is needed, in order, on demand.
 
<lang perl6>use ntheory:from<Perl5> <is_prime>;
Line 192 ⟶ 198:
++$po3;
@iterators.push: ([|((2,4,8).map: * * 3 ** $po3) … *]).iterator;
$add-one = @head[+@iterators - 1] = @iterators[+@iterators - 1].pull-one;
$add-one *= 3;
}
}
Line 204 ⟶ 211:
say "\n250th Pierpont prime of the first kind: " ~ pierpont[249];
 
say "\n250th Pierpont prime of the second kind: " ~ pierpont(2)[249];</lang>
 
# And the question absolutely noone was asking:
 
say "\n1000th Pierpont prime of the first kind:\n" ~ pierpont[999];
 
say "\n1000th Pierpont prime of the second kind:\n" ~ pierpont(2)[999];</lang>
{{out}}
<pre>First 50 Pierpont primes of the first kind:
Line 222 ⟶ 235:
250th Pierpont prime of the first kind: 62518864539857068333550694039553
 
250th Pierpont prime of the second kind: 4111131172000956525894875083702271</pre>
 
1000th Pierpont prime of the first kind:
69269314716439690250482558089997110961545818230232043107188537422260188701607997086273960899938499201024414931399264696270849
 
1000th Pierpont prime of the second kind:
1308088756227965581249669045506775407896673213729433892383353027814827286537163695213418982500477392209371001259166465228280492460735463423</pre>
 
=={{header|REXX}}==
10,333

edits