Fortunate numbers: Difference between revisions

Added Perl
(→‎{{header|REXX}}: added the computer programming language REXX.)
(Added Perl)
Line 167:
239 271 277 283 293 307 311 313 331 353
373 379 383 397 401 409 419 421 439 443</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>use strict;
use warnings;
use List::Util <first uniq>;
use ntheory qw<pn_primorial is_prime>;
 
my $upto = 50;
my @candidates;
for my $p ( map { pn_primorial($_) } 1..2*$upto ) {
push @candidates, first { is_prime($_ + $p) } 2..100*$upto;
}
 
my @fortunate = sort { $a <=> $b } uniq grep { is_prime $_ } @candidates;
 
print "First $upto distinct fortunate numbers:\n" .
(sprintf "@{['%6d' x $upto]}", @fortunate) =~ s/(.{60})/$1\n/gr;</lang>
{{out}}
<pre>First 50 distinct fortunate numbers:
3 5 7 13 17 19 23 37 47 59
61 67 71 79 89 101 103 107 109 127
151 157 163 167 191 197 199 223 229 233
239 271 277 283 293 307 311 313 331 353
373 379 383 397 401 409 419 421 439 443</pre>
 
=={{header|Phix}}==
2,392

edits