Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -8,7 +8,25 @@ function maxsub(ary, idx)
end
local v = maxsub(ary, idx + 1)
if maxsum < sumt(v, 1, #v) then return v end
local ret = {}
for i = idx, last do ret[#ret+1] = ary[i] end
return ret
local ret, allNegative = {}, true
for i = idx, last do
ret[#ret+1] = ary[i]
if ret[#ret] >= 0 then allNegative = false end
end
return allNegative and {} or ret
end
local function test(s)
local msub = maxsub(s)
print("["..table.concat(s, " ").."] -> ["..table.concat(msub, " ").."] sum: "..sumt(msub, 1, #msub))
end
-- test cases from 11l
test {-1, 2, -1}
test {-1, 2, -1, 3, -1}
test {-1, 1, 2, -5, -6}
test {-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1}
-- additional test cases
test {-1, -2, -1}
test {}