Commits

Shlomi Fish committed 4177f06

Made more progress, but it is still not working.

Comments (0)

Files changed (1)

project-euler/111/euler-111.pl

 use warnings;
 
 use List::Util qw(sum);
+use Math::GMP;
 
 sub is_prime
 {
 # print is_prime(5), "\n";
 # print is_prime(10), "\n";
 
+my $count_digits = 10;
+my @digits = (0 .. 9);
+my @non_zero_digits = (1 .. 9);
+
 my @S_10_d;
 MAIN_D_LOOP:
-foreach my $main_d (1 .. 9, 0)
+foreach my $main_d (0 .. 9)
 {
-    foreach my $other_digits (1 .. 9)
+    foreach my $num_other_digits (1 .. $count_digits-1)
     {
         my $sum = 0;
 
 
             if ($count == 0)
             {
-                $num_so_far .= ($main_d x (10 - length($num_so_far)));
-                if ($main_d == 1)
-                {
-                    print "Checking $num_so_far\n";
-                }
+                $num_so_far .= ($main_d x ($count_digits - length($num_so_far)));
+                # print "Checking $num_so_far\n";
                 if (is_prime($num_so_far))
                 {
                     $sum += $num_so_far;
             else
             {
                 my $start = length($num_so_far);
-                my $end = 10-$count;
+                my $end = $count_digits-$count;
 
                 for my $pos ($start .. $end)
                 {
-                    foreach my $d (0 .. 9)
+                    OTHER_DIGIT_LOOP:
+                    foreach my $d (@digits)
                     {
                         if ($d == $main_d)
                         {
-                            next;
+                            next OTHER_DIGIT_LOOP;
                         }
                         $iter->(
                             $count-1,
 
         if (1)
         {
-            for my $first_digit (1 .. 9)
+            for my $first_digit (@non_zero_digits)
             {
-                $iter->($other_digits - ($first_digit == $main_d), $first_digit);
+                $iter->($num_other_digits - ($first_digit != $main_d), $first_digit);
             }
         }
         else
         {
-            $iter->($other_digits, '');
+            $iter->($num_other_digits, '');
         }
 
 
         if ($sum > 0)
         {
             print "Found $sum\n";
+            print "M_$main_d = ", 10 - $num_other_digits, "\n";
             push @S_10_d, $sum;
             next MAIN_D_LOOP;
         }