summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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";