Skip to content

Instantly share code, notes, and snippets.

@vaibhavsagar
Created October 18, 2016 21:11
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 vaibhavsagar/adba3177547f2fa2e06a38e705fe9045 to your computer and use it in GitHub Desktop.
Save vaibhavsagar/adba3177547f2fa2e06a38e705fe9045 to your computer and use it in GitHub Desktop.
Week 10 with @zebesta
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