Commits

Shlomi Fish committed 811357b

Made more progress but there's a bug.

  • Participants
  • Parent commits 905421f

Comments (0)

Files changed (1)

File project-euler/101/euler-101-take2-with-bigrat.pl

     return;
 }
 
+sub as_string
+{
+    my $self = shift;
+
+    return join(", ", map { $_ . "" } @{$self->elems()});
+}
+
 package Matrix;
 
 use Moose;
     
     foreach my $i (0 .. $self->size()-1)
     {
-        $self->_elem($row_idx, $i) +=
-            ($multiplier * $self->_elem($other_row, $i));
+        my $e = $self->_elem($row_idx, $i);
+        
+        $e += ($multiplier * $self->_elem($other_row, $i));
     }
 }
 
     return $inverted;
 }
 
+sub as_string
+{
+    my $self = shift;
+
+    return join( "", map { $_->as_string() . "\n" } @{$self->rows()});
+}
+
 package main;
 
+use Data::Dumper;
 
+sub _row
+{
+    my $elems = shift;
+
+    return Row->new({ elems => [ map { Math::BigRat->new($_) } @{$elems}]});
+}
+
+my $mat = Matrix->new(
+    {
+    rows =>
+    [
+        _row([2,3,0]),
+        _row([0,1,0]),
+        _row([0,0,5]),
+    ]
+    }
+);
+
+print $mat->inv->as_string();