File: project_euler_037.pl

package info (click to toggle)
libmath-prime-util-perl 0.73-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,796 kB
  • sloc: perl: 24,676; ansic: 11,471; makefile: 26; python: 24
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";