Skip to content

Instantly share code, notes, and snippets.

@brendanmaguire
Last active August 4, 2017 12:43
Show Gist options
  • Save brendanmaguire/bdfe99e55b4bb89e777a7391a32b87f0 to your computer and use it in GitHub Desktop.
Save brendanmaguire/bdfe99e55b4bb89e777a7391a32b87f0 to your computer and use it in GitHub Desktop.
Solution to the APL problem posed @ https://www.meetup.com/FunctionalKubs/events/241891161/
⍝ Solution that takes a string which may contain parentheses:
⍝ * Get the maximum depth
⍝ * Check that it is balanced
depths←{+\(1 ¯1 0)['()'⍳⍵]}
balanced←{⌊/depths ⍵}
max_depth←{⌈/depths ⍵}
s1←'abc(def(ghi)(jkl(mno)pqr))'
s2←')(xxx(yyy)'
balanced s1
max_depth s1
balanced s2
max_depth s2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment