Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Largest Sum of Consecutive Integers

by Anonymous Monk
on Oct 13, 2008 at 20:27 UTC ( [id://716850]=note: print w/replies, xml ) Need Help??


in reply to Largest Sum of Consecutive Integers

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
  • Comment on Re: Largest Sum of Consecutive Integers

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://716850]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found