File: project_euler_037.pl

package info (click to toggle)
libmath-prime-util-perl 0.60-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,380 kB
  • ctags: 2,261
  • sloc: perl: 22,565; ansic: 8,478; python: 24; makefile: 12
file content (19 lines) | stat: -rw-r--r-- 438 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env perl
use warnings;
use strict;
use Math::Prime::Util qw/:all/;

my @tp;
my $p = 7;
while (1) {
  $p = next_prime($p);
  next unless $p =~ /^[2357]/ && $p =~ /[2357]$/;   # p ends are prime
  my $len = 1;
  while (++$len < length($p)) {
    last unless is_prime(substr($p, 0, $len)) && is_prime(substr($p, -$len));
  }
  next unless $len == length($p);
  push @tp, $p;
  last if scalar @tp >= 11;
}
print vecsum(@tp), "\n";