This question already has an answer here:

Consider a string like:


Write a program that will verify whether a string is correctly bracketed. A correctly bracketed string can be defined as one in which all brackets are terminated (closed), and the inner brackets are terminated before outer ones. Below are example strings:

Correctly bracketed:

  • a.push(a,{b,[c,d]})

Incorrectly bracketed:

  • a.push(a,{b)}

Your program must be able to deal with the following types of brackets:

  • Curly (flower) brackets {}
  • Square brackets []
  • Parantheses ()

If necessary, the string may contain any of these characters:

  • Alphabets, uppercase and lowercase (A-Z, a-z)
  • Numerics (0-9)
  • Double quotes ("), but not single quotes
  • Arithmetic operators (+, -, *, /)
  • Dots (.)

This is , so the shortest code in terms of bytes wins. The winning answer will be chosen after 7 days from the time of the post.


marked as duplicate by Shaggy code-golf Dec 8 '18 at 13:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Related or maybe even a duplicate. \$\endgroup\$ – nimi Dec 8 '18 at 13:13
  • 2
    \$\begingroup\$ Well written challenge, unfortunate conclusion. \$\endgroup\$ – Arnauld Dec 8 '18 at 13:33