News for hackers. Stuff that matters.
Re:A Brutal Look at Balanced Parentheses, Computing Machines... by Epholys on Friday February 22, 2019 @02:09PM (#19228139)
Yeah, that's the first solution that popped in my mind too. I think it needs just a special case at the beginning to check if the first paren is not a closing one.

EDIT: yep, after reading the comments below I see that I really should have put just a little more thought before dismissing this as too trivial to think about.

Re:A Brutal Look at Balanced Parentheses, Computing Machines... by braythwayt on Friday February 22, 2019 @02:25PM (#19228284)
The stack solution checks that the stack is non-empty before popping.

The counter solution simply needs to check that the counter is non-zero before decrementing.

All cases then work perfectly.

Re:A Brutal Look at Balanced Parentheses, Computing Machines... by FreeFull on Friday February 22, 2019 @02:25PM (#19228280)
What you actually need is to check if the count ever goes negative.
Re:A Brutal Look at Balanced Parentheses, Computing Machines... by skybrian on Friday February 22, 2019 @02:18PM (#19228207)
A test case: ())(