diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-05-16 02:06:11 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-05-16 02:06:11 -0500 |
commit | a847d7fe1f5425b5b2367bf5ca85d4cf049cb7af (patch) | |
tree | e472166be6bef4d9281c2f4b1ded6b177ae1dcb1 | |
parent | 67cb894a9ed7a752e21154282858f16f9567124d (diff) | |
download | projecteuler-a847d7fe1f5425b5b2367bf5ca85d4cf049cb7af.tar.gz projecteuler-a847d7fe1f5425b5b2367bf5ca85d4cf049cb7af.zip |
solution to 37
-rwxr-xr-x | 037.pl | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -0,0 +1,19 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Math::Prime::XS qw/sieve_primes/; +use List::MoreUtils qw/all/; + +my @primes = sieve_primes(1e6); +my %primes = map { $_, 1 } @primes; +my $total = 0; +for my $prime (@primes) { + next if $prime < 10; + my @potentials = grep { length } + map { substr($prime, 0, $_), + substr($prime, $_) } + 1..(length $prime); + next unless all { $primes{$_} } @potentials; + $total += $prime; +} +print "$total\n"; |