project-euler / project-euler / 147 / euler-147.pl

Diff from to

project-euler/147/euler-147.pl

 
 =cut
 
+# A 2-dimensional cache.
+# $Rects_Coefficients_Cache[$rect_x][$rect_y] = { min => $min, offset => $offset};
+# Formula for step is calculated at 2*$board_dim + $offset
+my @Rects_Coefficients_Cache;
+
 # A 4-dimensional cache:
 # 0 - board large dim.
 # 1 - board small dim.
 # 3 - rect large dim.
 # Each value is:
 # {
-my @Cache;
+#
+
+# Cache for the boards:
+# $Boards_Cache[$board_x][$board_y] = { 'num_unique' => , 'rects' => \@rects, }
+# rects is:
+# $rects[$rect_x][$rect_y]
+my @Boards_Cache;
 
 sub get_unique_rects
 {
     # $x >= $y >= $rect_x , $rect_y
     my ($x, $y, $rect_x, $rect_y) = @_;
 
-    my $struct = ($Cache[$x][$y][$rect_x][$rect_y] //= {});
+    my $board_struct = ($Boards_Cache[$x][$y] //= +{});
 
-    # No longer needed because calculated directly in get_total_rects()
-    # my $unique_num_straight = ($x-$rect_x+1) * ($y-$rect_y+1);
-    # $struct->{unique_num_straight} = $unique_num_straight;
-    #
+    if (! defined($board_struct->{num_unique}))
+    {
+        # Calculate the unique rectangles.
+        $board_struct->{rects} //= [];
+    }
 
-
-
-    return $struct;
+    return $board_struct;
 }
 
 sub get_total_rects
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.