Shlomi Fish avatar Shlomi Fish committed 1309df2

Another optimisation.

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

Comments (0)

Files changed (1)

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

 
 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.