Commits

Shlomi Fish  committed 68747f0

Solved Euler 150.

  • Participants
  • Parent commits 3485d81

Comments (0)

Files changed (2)

File project-euler/150/Euler150.pm

     return ($t - (1 << 19));
 }
 
+package Euler150;
+
+use strict;
+use warnings;
+
+use integer;
+
+use List::Util qw(min);
+
+sub solve
+{
+    my @sums = ();
+    my $min = 0;
+
+    foreach my $row_idx (0 .. (1_000 - 1))
+    {
+        print "Checking row $row_idx\n";
+        my $row_sum = 0;
+        my @row = ($row_sum);
+        foreach my $i (0 .. $row_idx)
+        {
+            push @row, ($row_sum += Euler150::S::get());
+        }
+
+        my $tri_idx = 0;
+        foreach my $r (0 .. $row_idx)
+        {
+            foreach my $col (0 .. $r)
+            {
+                $min = min($min, 
+                    ($sums[$tri_idx] += $row[$col+$row_idx-$r+1] - $row[$col])
+                );
+                $tri_idx++;
+            }
+        }
+        print "Min = $min\n";
+    }
+}
 1;

File project-euler/150/euler-150.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Euler150;
+
+Euler150::solve();