summaryrefslogtreecommitdiffstats
path: root/043.pl
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-19 21:43:30 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-19 21:43:30 -0500
commit279975c1fd05b2455b017a49521e34c64623b05e (patch)
tree0bdc8d44f0079f730d007ad4b0bb1ed48b082bb3 /043.pl
parentb34c80e0be08ea4d9c5533cfd525d2181bed35b5 (diff)
downloadprojecteuler-279975c1fd05b2455b017a49521e34c64623b05e.tar.gz
projecteuler-279975c1fd05b2455b017a49521e34c64623b05e.zip
solution for 43
Diffstat (limited to '043.pl')
-rwxr-xr-x043.pl20
1 files changed, 20 insertions, 0 deletions
diff --git a/043.pl b/043.pl
new file mode 100755
index 0000000..1d5607b
--- /dev/null
+++ b/043.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Math::Combinatorics;
+use integer;
+
+my $comb = Math::Combinatorics->new(data => [0..9]);
+my @numbers;
+while (my @perm = $comb->next_permutation) {
+ next unless (100 * $perm[1] + 10 * $perm[2] + $perm[3]) % 2 == 0;
+ next unless (100 * $perm[2] + 10 * $perm[3] + $perm[4]) % 3 == 0;
+ next unless (100 * $perm[3] + 10 * $perm[4] + $perm[5]) % 5 == 0;
+ next unless (100 * $perm[4] + 10 * $perm[5] + $perm[6]) % 7 == 0;
+ next unless (100 * $perm[5] + 10 * $perm[6] + $perm[7]) % 11 == 0;
+ next unless (100 * $perm[6] + 10 * $perm[7] + $perm[8]) % 13 == 0;
+ next unless (100 * $perm[7] + 10 * $perm[8] + $perm[9]) % 17 == 0;
+ push @numbers, join '', @perm;
+}
+my $sum = join '+', @numbers;
+print qx{echo $sum | bc};