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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sum of continues array
by sanku (Beadle) on Sep 10, 2008 at 08:16 UTC | |
by Zen (Deacon) on Sep 10, 2008 at 15:24 UTC |