Skip to content

Instantly share code, notes, and snippets.

@diegoeche
Created December 18, 2014 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegoeche/0cb7dab3dd7ce3ec6266 to your computer and use it in GitHub Desktop.
Save diegoeche/0cb7dab3dd7ce3ec6266 to your computer and use it in GitHub Desktop.
import Data.List
removeNegatives = filter $ not . (< 0) . head
removeEmpties = filter $ not . null
safeTail (x:xs) = xs
safeTail x = x
parts [] = []
parts x = inits x ++ (parts $ safeTail $ x)
testCases = [[1,2,3,0,-8,1,2,4],[-2,1,2,3,0,-5,1,2,4],[-2,1,-3,4,-1,2,1,-5,4]]
main = print ((maximum . (map sum) . removeNegatives. removeEmpties . parts) `map` testCases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment