Skip to content

Instantly share code, notes, and snippets.

@rockneurotiko
Created March 11, 2016 10:46
Show Gist options
  • Save rockneurotiko/41900abc86a3afb53462 to your computer and use it in GitHub Desktop.
Save rockneurotiko/41900abc86a3afb53462 to your computer and use it in GitHub Desktop.
// Part one
println(io.StdIn.readLine.foldLeft(0) {
case (cur, '(') => cur + 1
case (cur, ')') => cur - 1
case (cur, _) => cur
})
// Part two
println(io.StdIn.readLine.scanLeft(0) {
case (cur, '(') => cur + 1
case (cur, ')') => cur - 1
case (cur, _) => cur
}.indexOf(-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment