Jump to content

Substring primes: Difference between revisions

Line 290:
Discarded candidates: [27, 57, 237, 537, 737]
</pre>
 
=={{header|Perl}}==
<lang perl>#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Substring_primes
use warnings;
 
my %prime;
 
LOOP:
for (2 .. 500 )
{
my %substrings = ();
/.+(?{ $prime{$&} or $substrings{$&}++ })(*FAIL)/;
for my $try ( sort { $a <=> $b } keys %substrings )
{
$try < 2 and next LOOP;
$prime{$try} || (1 x $try) !~ /^(11+)\1+$/ ? $prime{$try}++ : next LOOP;
}
}
printf " %d" x %prime . "\n", sort {$a <=> $b} keys %prime;</lang>
{{out}}
2 3 5 7 23 37 53 73 373
 
 
=={{header|Phix}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.