Last active
December 26, 2015 08:59
-
-
Save Yacoby/7126279 to your computer and use it in GitHub Desktop.
Get the value of the maximum sublist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maxSublist :: [Integer] -> Integer | |
maxSublist = fst . foldr (\x (curValue, maxValue) -> (maximum [0, curValue + x], maximum [curValue + x, maxValue])) (0,0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maxSublist = fst . foldr (`ap` snd) . (. fst) . ap (ap . (((.) . (,) . max . (0 :)) .) . flip flip [] . ((:) .) . (+)) (((max .) .) . flip flip return . (((.) . (:)) .) . (+)) (0,0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment