Skip to content

Instantly share code, notes, and snippets.

@Yacoby
Last active December 26, 2015 08:59
Show Gist options
  • Save Yacoby/7126279 to your computer and use it in GitHub Desktop.
Save Yacoby/7126279 to your computer and use it in GitHub Desktop.
Get the value of the maximum sublist
maxSublist :: [Integer] -> Integer
maxSublist = fst . foldr (\x (curValue, maxValue) -> (maximum [0, curValue + x], maximum [curValue + x, maxValue])) (0,0)
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