Last active
August 4, 2017 12:43
-
-
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/
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
⍝ 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