Pierpont primes: Difference between revisions
Content added Content deleted
(julia example) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Rearrange a bit, move stuff out of the hot loop, cut runtime by ~40%) |
||
Line 215: | Line 215: | ||
<lang perl6>use ntheory:from<Perl5> <is_prime>; |
<lang perl6>use ntheory:from<Perl5> <is_prime>; |
||
sub pierpont ($ |
sub pierpont ($kind is copy = 1) { |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
my $add-one = 3; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
my @head = @iterators».pull-one; |
my @head = @iterators».pull-one; |
||
Line 231: | Line 231: | ||
@head[$key] = @iterators[$key].pull-one; |
@head[$key] = @iterators[$key].pull-one; |
||
take $min + $ |
take $min + $kind if "{$min + $kind}".&is_prime; |
||
if $min >= $add-one { |
if $min >= $add-one { |
||
++$po3; |
|||
@iterators.push: ([|((2,4,8).map: * * 3 ** $po3) … *]).iterator; |
|||
@head[+@iterators - 1] = @iterators[+@iterators - 1].pull-one; |
$add-one = @head[+@iterators - 1] = @iterators[+@iterators - 1].pull-one; |
||
$add-one *= 3; |
|||
} |
} |
||
} |
} |
||
Line 251: | Line 250: | ||
say "\n250th Pierpont prime of the second kind: " ~ pierpont(2)[249]; |
say "\n250th Pierpont prime of the second kind: " ~ pierpont(2)[249]; |
||
# And the question absolutely |
# And the question absolutely nobody was asking: |
||
say "\n1000th Pierpont prime of the first kind:\n" ~ pierpont[999]; |
say "\n1000th Pierpont prime of the first kind:\n" ~ pierpont[999]; |