summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-16 02:06:11 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-16 02:06:11 -0500
commita847d7fe1f5425b5b2367bf5ca85d4cf049cb7af (patch)
treee472166be6bef4d9281c2f4b1ded6b177ae1dcb1
parent67cb894a9ed7a752e21154282858f16f9567124d (diff)
downloadprojecteuler-a847d7fe1f5425b5b2367bf5ca85d4cf049cb7af.tar.gz
projecteuler-a847d7fe1f5425b5b2367bf5ca85d4cf049cb7af.zip
solution to 37
-rwxr-xr-x037.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/037.pl b/037.pl
new file mode 100755
index 0000000..f20b2c8
--- /dev/null
+++ b/037.pl
@@ -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";