ARarthurcolle·Feb 23, 2019
https://github.com/stochastic-thread/balanced_parentheses/bl...
What do you think of this implementation I just wrote? It is generalized to work with parentheses, brackets and braces, and to handle the different types of braces I just used different scores that offset each other depending on the direction of the symbol. Couldn't really think of a better way to handle this other than using numbers that don't add up to one another (in a momentary fugue state, I used 1,-1,2,-2,3,-3 as the score values but that obviously doesn't work as [}) would be false flagged as matched. Doesn't seem elegant to use random floats to accomplish this.
It's a pretty trivial problem, but I think coming up with a clever solution to the generalization is a little more interesting.
P.S. your site is down
In A Brutal Look at Balanced Parentheses, Computing Machines, and Pushdown Automata