Commits

Shlomi Fish  committed 9ba3df5

Finished Euler #148!

See Calc.pl and calc-num-Y-in-row-ORIG-2.pl.

  • Participants
  • Parent commits 1049eb7

Comments (0)

Files changed (3)

File project-euler/148/148-analysis.txt

 
 \|Triangle[50[1 .. 48] .. 98[48]] = (1+48)*48/2 Ys ==> 1176 Ys
 
-Triangle[1 .. 49*7] = Triangle[1 .. 343] = (1+7)*7/2*Triangle[1..49] + (1+6)*6/2 * \|Triangle[50 .. 98] = 
+Triangle[1 .. 49*7] = Triangle[1 .. 343] = (1+7)*7/2*Triangle[1..49] + (1+6)*6/2 * \|Triangle[50 .. 98] =
+
+==============================================
+
+Sum [1e9+1 .. 1008840175] == 8808901168440968
+ImproperImproperTriangle[1 .. 1008840175] = 506678931013126536
+
+Total[N] = (1+1e9)*1e9/2 - (506678931013126536 - 8808901168440968)
+
+$ perl -E 'use integer; say +(1+1e9)*1e9/2 - (506678931013126536 - 8808901168440968)'
+2129970655314432
+

File project-euler/148/Calc.pl

 
 my @stack = ();
 
-# my $LIMIT = 1_000_000_000;
-my $LIMIT = 100;
+my $LIMIT = 1_000_000_000;
+# my $LIMIT = 100;
 
 while ($power < $LIMIT)
 {

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

 
 if ($ENV{RUN})
 {
-    my $LIMIT = 1_000_000_000;
+    my $START = 1_000_000_001;
+    my $LIMIT = 1_008_840_175;
     my $limit = $LIMIT / $B;
     my $sum = 0;
 
     my $n;
-    foreach my $d (847_425_747/7 .. $limit)
+
+    my $i = $START;
+    while (($i % $B) != 1)
     {
-        $n = $d * $B + 1;
-        $sum += calc_num_Y_in_7_consecutive_rows($n);
+        $sum += calc_num_Y_in_row_n($i);
+        $i++;
+    }
+    my $e = $LIMIT;
+    while (($e % $B) != 1)
+    {
+        $sum += calc_num_Y_in_row_n($e);
+        $e--;
+    }
+    # We don't calculate that in the 7 step loop.
+    $sum += calc_num_Y_in_row_n($e);
 
-        if ($d % 10_000 == 0)
+    my $next_i = $i + 10_000;
+    while ($i < $e)
+    {
+        $sum += calc_num_Y_in_7_consecutive_rows($i);
+        if ($i >= $next_i)
         {
-            print "Reached $n [Sum == $sum]\n";
+            print "Reached $i [Sum == $sum]\n";
+            $next_i += 10_000;
         }
+        $i += 7;
     }
-
-    $sum += sum(map { calc_num_Y_in_row_n($_) } ($n .. $LIMIT));
     print "Final Sum == $sum\n";
 }
 elsif ($ENV{TEST})