Created
October 18, 2016 21:11
-
-
Save vaibhavsagar/adba3177547f2fa2e06a38e705fe9045 to your computer and use it in GitHub Desktop.
Week 10 with @zebesta
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
sherlock :: Int -> Int -> Int -> [Int] -> Bool | |
sherlock left current sm [] = | |
if left == sm | |
then True | |
else False | |
sherlock left current sm rest = | |
case compare left sm of | |
LT -> let | |
left' = left + current | |
current':rest' = rest | |
sm' = sm - current' | |
in sherlock left' current' sm' rest' | |
EQ -> True | |
GT -> False | |
sherlock' ls = let | |
left = 0 | |
current:rest = ls | |
sm = sum rest | |
in sherlock left current sm rest | |
sherlock'' ls = if sherlock' ls then "YES" else "NO" | |
main = do | |
numCases <- fmap read getLine :: IO Int | |
mapM (\_ -> do | |
getLine | |
input <- getLine | |
let numbers = map read $ words input :: [Int] | |
putStrLn (sherlock'' numbers) | |
) [1..numCases] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment