Prime triplets: Difference between revisions

(Added XPL0 example.)
Line 445:
use strict;
use warnings;
use ntheory qw( is_prime twin_primes );
 
is_prime($_ + 6) and printf "%5d" x 3 . "\n", $_, $_ + 2, $_ + 6;
my %cache;
for @{ twin_primes( 5500 ) };</lang>
sub isprime { $cache{$_[0]} //= (1 x $_[0]) =~ /^(11+)\1+$/ ? 0 : 1 }
 
for ( 3 .. 5500 )
{
$_ & 1 and isprime($_+6) and isprime($_+2) and isprime($_) and
printf "%5d" x 3 . "\n", $_, $_ + 2, $_ + 6;
}</lang>
{{out}}
<pre>
Anonymous user