September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,6 +1,8 @@
maxsubseq = snd . foldl f ((0,[]),(0,[])) where
f ((h1,h2),sofar) x = (a,b) where
a = max (0,[]) (h1 + x, h2 ++ [x])
b = max sofar a
maxSubseq :: [Int] -> (Int, [Int])
maxSubseq =
let go x ((h1, h2), sofar) =
((,) <*> max sofar) (max (0, []) (h1 + x, x : h2))
in snd . foldr go ((0, []), (0, []))
main = print $ maxsubseq [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]
main :: IO ()
main = print $ maxSubseq [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]