Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^3: Largest Sum of Consecutive Integers (abstraction)by johnnywang (Priest) |
on Aug 31, 2006 at 17:53 UTC ( [id://570652]=note: print w/replies, xml ) | Need Help?? |
Another observation is that you can always add the consecutive postive or negative numbers together, so you only need to deal with the case when the sequence is alternating, +-+-+-+-...+. That may simplify the logic. But tilly's solution is certainly elegant, the only "drawback" is that it's not symmetric, would be more beautiful if it went from both ends.
In Section
Seekers of Perl Wisdom
|
|