Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,10 @@
import Data.List (inits, tails, maximumBy)
import Data.Ord (comparing)
subseqs :: [a] -> [[a]]
subseqs = concatMap inits . tails
maxsubseq :: (Ord a, Num a) => [a] -> [a]
maxsubseq = maximumBy (comparing sum) . subseqs
main = print $ maxsubseq [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]

View file

@ -0,0 +1,8 @@
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 :: IO ()
main = print $ maxSubseq [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]