Last active
December 4, 2015 17:03
-
-
Save pjrt/ddb49b19904704c1a7c3 to your computer and use it in GitHub Desktop.
equi in Haskell
This file contains hidden or 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
equi :: [Int] -> Maybe Int | |
equi [] = Nothing | |
equi ns = go 0 0 ns | |
where | |
fullSum = sum ns | |
go _ _ [] = Nothing | |
go n leftSum (x:xs) = | |
let rightSum = fullSum - leftSum - x | |
in if rightSum == leftSum | |
then Just n | |
else go (n + 1) (leftSum + x) xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment