There's more than one way to do things | |
PerlMonks |
Re: Largest Sum of Consecutive Integersby Anonymous Monk |
on Oct 13, 2008 at 20:27 UTC ( [id://716850]=note: print w/replies, xml ) | Need Help?? |
Hi Every One, I have improved my algorithm going from back to forward, but this time it also goes from left to right. You keep a current max, and current sum 3 2 8 9 -25 5 8 4 4 -3 5 3 -10 current sum 3 5 13 22 0 5 13 17 21 18 23 26 16 current max 3 5 13 22 22 22 22 22 22 22 23 26 26 When I reach -25. I update current sum and it is negtiave, so I start the current sum from here again from scratch. This method can even accept infinite numbers coming from an outside source, so it is on the fly algorithm which uses greedy methods Ilteris Murat Derici & David Matula
In Section
Seekers of Perl Wisdom
|
|