summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-19 23:35:25 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-19 23:35:25 -0500
commitaf5977b0b378e30149a51bc93b1d6db1addc161c (patch)
tree0330afe33f2b41bf07d748d246eb3fc6fcea3a28
parent910b24fd10c1075640f1fbbbafac0b33b779e363 (diff)
downloadprojecteuler-af5977b0b378e30149a51bc93b1d6db1addc161c.tar.gz
projecteuler-af5977b0b378e30149a51bc93b1d6db1addc161c.zip
41 solved... 1-50 are done now!
-rwxr-xr-x041.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/041.pl b/041.pl
new file mode 100755
index 0000000..b53825b
--- /dev/null
+++ b/041.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Math::Prime::XS qw/sieve_primes/;
+use Math::Combinatorics;
+
+my @primes = sieve_primes(8e6);
+my %primes = map { $_, 1 } @primes;
+
+my $max = 0;
+# can skip 8 and 9 because 36 and 45 are divisible by 3
+for my $n (reverse 2..7) {
+ my $comb = Math::Combinatorics->new(data => [1..$n]);
+ while (my $perm = join '', $comb->next_permutation) {
+ $max = $perm if $perm > $max && exists $primes{$perm};
+ }
+ last if $max;
+}
+print "$max\n";