Shlomi Fish avatar Shlomi Fish committed 9fa289b

Add Euler 147 analysis

Comments (0)

Files changed (2)

project-euler/147/euler-147-analysis.txt

+The vertical/horizontal number of rectangles is trivial:
+
+If the rectangle dimensions are  s[x],s[y] and the board dimensions are
+b[x], b[y] then there are ( b[x] - (s[x] - 1) ) * ( b[y] - (s[y] - 1) )
+squares there of that size.
+
+Now for the diagonal squares:
+

project-euler/148/148.pl

 my $prev_row = '';
 my $next_row = '';
 
+my @mod = (map { my $y = $_; [map { ($y+$_)%7 } (0 .. 6)] } (0 .. 6));
+
 my $result_count = 0;
 # while ($row_count++ <= 1_000_000_000)
-vec($prev_row, 0, 4) = 1;
+vec($prev_row, 0, 8) = 1;
 $result_count++;
 while ($prev_row_count < 1_000_000_000)
 {
     {
         print "Reached $prev_row_count\n";
     }
-    vec($next_row, 0, 4) = 1;
+    vec($next_row, 0, 8) = 1;
     for my $i (1 .. $prev_row_count-1)
     {
         if (
-        vec($next_row, $i, 4) =
-            ((vec($prev_row, $i-1, 4) + vec($prev_row, $i, 4)) % 7)
+        vec($next_row, $i, 8) = $mod[vec($prev_row, $i-1, 8)][vec($prev_row, $i, 8)]
         )
         {
             $result_count++;
         }
     }
-    vec($next_row, $prev_row_count, 4) = 1;
+    vec($next_row, $prev_row_count, 8) = 1;
     # For the two 1s on the sides of the row.
     $result_count += 2;
 }
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.