Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code Dojo solution
import Data.List (inits, tails)
partitionSum [] n = n
partitionSum ls n = let
pairs = zip (tail $ inits ls) (tail $ tails ls)
pass = filter (\(l,r) -> (sum l) == (sum r)) pairs
maxes = map (\(l,r) -> max (partitionSum l (n+1)) (partitionSum r (n+1))) pass
in if (maxes == []) then n else (maximum maxes)
main = do
noCases <- fmap read getLine :: IO Int
mapM_ (\_ -> do
_ <- getLine
ls' <- fmap words getLine
let ls = map read ls' :: [Int]
print $ partitionSum ls 0) [1..noCases]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment