Greatest subsequential sum: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: replaced `.each_with_index` with `.each_kv`) |
|||
Line 2,729: | Line 2,729: | ||
<lang ruby>func maxsubseq(*a) { |
<lang ruby>func maxsubseq(*a) { |
||
var (start, end, sum, maxsum) = (-1, -1, 0, 0); |
var (start, end, sum, maxsum) = (-1, -1, 0, 0); |
||
a. |
a.each_kv { |i, x| |
||
sum += x; |
sum += x; |
||
if (maxsum < sum) { |
if (maxsum < sum) { |