Last active
February 25, 2017 23:35
-
-
Save mdomke/32bb9bf982fee4ac133eb4f71d4b5e27 to your computer and use it in GitHub Desktop.
equi function in haskell
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
import Data.List | |
-- | Find the index corresponding to the equilibrium point of a | |
-- list. This is where the sum of the values to the left of the | |
-- index equals the sum of the values to the right. | |
equi :: [Int] -> Maybe Int | |
equi xs = findIndex match $ scanl (+) 0 xs | |
where match x = x * 2 == sum xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment