Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,21 @@
'''Greatest subsequential sum'''
from functools import (reduce)
# maxSubseq :: [Int] -> [Int] -> (Int, [Int])
def maxSubseq(xs):
'''Subsequence of xs with the maximum sum'''
def go(ab, x):
(m1, m2) = ab[0]
hi = max((0, []), (m1 + x, m2 + [x]))
return (hi, max(ab[1], hi))
return reduce(go, xs, ((0, []), (0, [])))[1]
# TEST -----------------------------------------------------------
print(
maxSubseq(
[-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]
)
)