Nice primes: Difference between revisions

Content added Content deleted
(Added Raku)
(Added Perl)
Line 383: Line 383:
The total found was 33
The total found was 33
</pre>
</pre>

=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>use strict;
use warnings;

use ntheory 'is_prime';
use List::Util qw(sum);

sub digital_root {
my ($n) = @_;
do { $n = sum split '', $n } until 1 == length $n;
$n
}

my($low, $high, $cnt, @nice_primes) = (500,1000);
is_prime($_) and is_prime(digital_root($_)) and push @nice_primes, $_ for $low+1 .. $high-1;

$cnt = @nice_primes;
print "Nice primes between $low and $high (total of $cnt):\n" .
(sprintf "@{['%5d' x $cnt]}", @nice_primes[0..$cnt-1]) =~ s/(.{55})/$1\n/gr;</lang>
{{out}}
<pre>Nice primes between 500 and 1000 (total of 33):
509 547 563 569 587 599 601 617 619 641 653
659 673 677 691 709 727 743 761 797 821 839
853 857 887 907 911 929 941 947 977 983 997</pre>


=={{header|Phix}}==
=={{header|Phix}}==