1. Shlomi Fish
  2. project-euler

Commits

Shlomi Fish  committed 1309df2

Another optimisation.

This time I got rid of the x_lim,y_lim,z_lim calcualations.

  • Participants
  • Parent commits e0c455a
  • Branches default

Comments (0)

Files changed (1)

File project-euler/126/euler-126-take3.pl

View file
 
 sub add_layer
 {
-    my ($x_lim, $y_lim, $z_lim) = @_;
-
-    my $key = "$x_lim,$y_lim,$z_lim";
+    my ($key) = @_;
 
     my $rec = $cuboids{$key};
 
-    return add_count($rec->{n} += ((($x_lim+$y_lim+$z_lim)<<2) + ($rec->{d} += 8)));
+    return add_count($rec->{n} += ($rec->{d} += 8));
 }
 
 sub add_count
             my $new_layer_count = 
                 (($x*$y+$x*$z+$z*$y)<<1);
 
-            # We increase the depth by 8 each time.
+            # We increase the depth's delta by 8 each time.
             $cuboids{"$x,$y,$z"} =
-                { d => -8, n => $new_layer_count};
+                { d => ((($x+$y+$z)<<2)-8), n => $new_layer_count};
 
             add_count($new_layer_count);
         }
 
     foreach my $dims (@to_update)
     {
-        add_layer (split(/,/, $dims));
+        add_layer ($dims);
     }
 }
 continue