Task:

 Generate a string with   N   opening brackets   [   and with   N   closing brackets   ],   in some arbitrary order. 
 Determine whether the generated string is balanced; that is, whether it consists entirely of pairs of opening/closing brackets (in that order), none of which mis-nest.


Examples

   (empty)      OK
   []           OK   
   [][]         OK   
   [[][]]       OK 
   ][         NOT OK
   ][][       NOT OK
   []][[]     NOT OK



s$ = "[[]][]"
print s$; " = ";
 
if not check_brackets(s$) then print "not ";
print "ok"
end
 
function check_brackets(s$)
  level = 0
  for i = 1 to length(s$)
    c$ = mid(s$, i, 1)
    begin case
      case c$ = "["
        level = level + 1
      case c$ = "]"
        level = level - 1
        if level < 0 then exit for
    end case
  next i
  return level = 0
end function