Substring primes: Difference between revisions
Content added Content deleted
Catskill549 (talk | contribs) |
|||
Line 290: | Line 290: | ||
Discarded candidates: [27, 57, 237, 537, 737] |
Discarded candidates: [27, 57, 237, 537, 737] |
||
</pre> |
</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}}== |
=={{header|Phix}}== |