Introduction
Given a String containing an arithmetic expression, your task is to output a truthy or falsey value based on whether it contains unmatched parentheses.
Input
Your program should take in a String containing an arithmetic expression. It may take input in any way except assuming it to be present in a pre-defined variable. Reading from file, input box, modal dialog box etc. is fine. Taking input as function argument is allowed as well!
Output
Your program should output a truthy or falsey value based on whether the input String contains any unmatched parentheses. It may output in any way except except writing to a variable. Writing to file, screen, console, terminal etc. is allowed. Outputting with function return
is allowed as well!
Rules
For the purpose of this challenge, a parentheses is defined as any one of
[
,{
,(
,)
,}
,]
. A parentheses is said to be unmatched if it does not have any corresponding opening/closing parentheses. For example,[1+3
does contain unmatched parentheses.Ordering of parentheses does not matter in this challenge. So,
]1+3[
does not contain any unmatched parentheses.{[)(}]
doesn't, as well.The input String will only contain following characters :
{
,[
,(
,)
,]
,}
,1
,2
,3
,4
,5
,6
,7
,8
,9
,0
,+
,-
,*
,/
and^
.Your program should output a truthy value if the input String contains an unmatched parentheses.
Your program should output a falsey value if the input String does not contain an unmatched parentheses.
You must specify the truthy and falsey values in your post.
The input String will never be empty.
If the input String does not contain any parentheses, your program should output falsey value.
Standard loopholes apply.
Test Cases
Input -> Output
"{" Truthy
"{{{{}}" Truthy
"{[]}" Falsey
"[]][" Falsey
")()()()(" Falsey
"1+4" Falsey
"{)" Truthy
"([)]" Falsey
"(()" Truthy
"2*{10+4^3+(10+3)" Truthy
"-6+[18-{4*(9-6)}/3]" Falsey
"-6+[18-{4*)9-6](/3}" Falsey
Winning Criterion
This is code-golf, so the shortest code in bytes wins!
Note
I'll be adding a similar challenge but in which order will matter, after some time! Stay Tuned!
][
or([)]
would be valid in the other challenge but are valid here. \$\endgroup\$