Skip to content

Instantly share code, notes, and snippets.

@dionyziz
Last active March 12, 2019 20:54
Show Gist options
  • Save dionyziz/c4225ba098e3de3e45b65e6787fe81e8 to your computer and use it in GitHub Desktop.
Save dionyziz/c4225ba098e3de3e45b65e6787fe81e8 to your computer and use it in GitHub Desktop.
count_parens s = fst $ foldl cnt (0, [0]) s
where cnt (i, acc) '(' = (i, 0:acc)
cnt (i, [x]) ')' = (i, [0])
cnt (i, a:b:bs) ')' = (i + b + 1, (b + 1):bs)
main = print $ count_parens "(())()"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment