Commits

Shlomi Fish  committed e8a1632

More optimisation.

  • Participants
  • Parent commits 4f513db

Comments (0)

Files changed (1)

File project-euler/149/149-opt1.pl

 
 package Max;
 
+# s = so far
+# e = ending here.
 sub new
 {
-    return bless { _so_far => 0, _ending_here => 0 }, shift;
+    return bless { s => 0, e => 0 }, shift;
 }
 
 sub _max
 {
     my ($self, $n) = @_;
  
-    $self->{_ending_here} = _max($self->{_ending_here} + $n, 0);
-    $self->{_so_far} = _max($self->{_so_far}, $self->{_ending_here});
+    $self->{'s'} = _max($self->{'s'}, ($self->{e} = _max($self->{e} + $n, 0)));
 
     return;
 }
 {
     my ($self) = @_;
 
-    return $self->{_so_far};
+    return $self->{'s'};
 }
 
 package main;