in reply to sum of continues array

See what teach makes of this :)

Update: Corrected logic from 'add if larger than last value' to 'add if larger than last value added.

#! perl -slw use strict; use List::Util qw[ reduce ];; my @array=(1,2,3,4,-1,-2,-3,11,12,13);; my $sum = @{ reduce{ @{ $a } = ( $a->[0]+$b, $b ) if $b > $a->[1]; $a; } [0, -9e99 ], @array }[0]; print $sum;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: sum of continues array
by sanku (Beadle) on Sep 10, 2008 at 08:16 UTC
    Thank you. it's working fine.
      I'm sure it is working fine, until your teacher realizes how advanced the technique is for your level and googles it. Your academic career worth it?