Commits

Shlomi Fish committed 0150fc2

Optimisation.

Comments (0)

Files changed (1)

project-euler/148/calc-num-Y-in-row.pl

     $recurse = sub {
         my ($d_len) = @_;
 
-        if ($d_len <= 1)
+        if ($d_len <= 0)
         {
             return 0;
         }
         else
         {
-            my $big_Y_num = ($digits[$d_len-1]->{power}-1-$digits[$d_len-2]->{total_mod});
-            my $big_Y_total = $big_Y_num * $digits[$d_len-1]->{d};
+            my $big_Y_num = ($digits[$d_len]->{power}-1-$digits[$d_len-1]->{total_mod});
+            my $big_Y_total = $big_Y_num * $digits[$d_len]->{d};
 
-            return $big_Y_total + ($digits[$d_len-1]->{d}+1) * $recurse->($d_len-1);
+            return $big_Y_total + ($digits[$d_len]->{d}+1) * $recurse->($d_len-1);
         }
     };
 
-    return $recurse->(scalar( @digits ));
+    return $recurse->($#digits);
 }
 
 foreach my $n (@ARGV)