Additive primes: Difference between revisions
Content added Content deleted
(Realize in F#) |
SqrtNegInf (talk | contribs) (Added Perl) |
||
Line 325: | Line 325: | ||
54 additive primes found. |
54 additive primes found. |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
|||
{{libheader|ntheory}} |
|||
<lang perl>use strict; |
|||
use warnings; |
|||
use ntheory 'is_prime'; |
|||
use List::Util <sum max>; |
|||
sub pp { |
|||
my $format = ('%' . (my $cw = 1+length max @_) . 'd') x @_; |
|||
my $width = ".{@{[$cw * int 60/$cw]}}"; |
|||
(sprintf($format, @_)) =~ s/($width)/$1\n/gr; |
|||
} |
|||
my($limit, @ap) = 500; |
|||
is_prime($_) and is_prime(sum(split '',$_)) and push @ap, $_ for 1..$limit; |
|||
print @ap . " additive primes < $limit:\n" . pp(@ap);</lang> |
|||
{{out}} |
|||
<pre>54 additive primes < 500: |
|||
2 3 5 7 11 23 29 41 43 47 61 67 83 89 101 |
|||
113 131 137 139 151 157 173 179 191 193 197 199 223 227 229 |
|||
241 263 269 281 283 311 313 317 331 337 353 359 373 379 397 |
|||
401 409 421 443 449 461 463 467 487</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |