Greatest subsequential sum: Difference between revisions

m
→‎{{header|Haskell}}: Reduced two nested `where` expressions to a single `let in` with a `<*>`
(→‎Functional Python: pylinted for Python 3, added {Works with} tag)
m (→‎{{header|Haskell}}: Reduced two nested `where` expressions to a single `let in` with a `<*>`)
Line 1,433:
Secondly, the linear time constant space approach:
<lang haskell>maxSubseq :: [Int] -> (Int, [Int])
maxSubseq = snd . foldr go ((0, []), (0, []))
let go x ((h1, h2), sofar) =
where
go x ((h1, h2), <*> max sofar) =(max (high0, max[]) sofar(h1 high+ x, x : h2))
in snd . foldr go ((0, []), (0, []))
where
high = max (0, []) (h1 + x, x : h2)
 
main :: IO ()
9,659

edits