Jump to content

Sum of primes in odd positions is prime: Difference between revisions

Added Perl
(Added Perl)
Line 171:
119 653 17959
143 823 26879</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>use strict;
use warnings;
use ntheory 'is_prime';
 
my $c;
my @odd = grep { 0 != ++$c % 2 } grep { is_prime $_ } 2 .. 999;
my @sums = $odd[0];
push @sums, $sums[-1] + $_ for @odd[1..$#odd];
 
$c = 1;
for (0..$#sums) {
printf "%6d%6d%6d\n", $c, $odd[$_], $sums[$_] if is_prime $sums[$_];
$c += 2;
}</lang>
{{out}}
<pre> 1 2 2
3 5 7
11 31 89
27 103 659
35 149 1181
67 331 5021
91 467 9923
95 499 10909
99 523 11941
119 653 17959
143 823 26879</pre>
 
=={{header|Phix}}==
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.