Skip to content

Instantly share code, notes, and snippets.

@mdomke
Last active February 25, 2017 23:35
Show Gist options
  • Save mdomke/32bb9bf982fee4ac133eb4f71d4b5e27 to your computer and use it in GitHub Desktop.
Save mdomke/32bb9bf982fee4ac133eb4f71d4b5e27 to your computer and use it in GitHub Desktop.
equi function in haskell
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