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



FOR len = 0 TO 18 STEP 2
 
    str$ = ""
    DOTIMES len
        str$ = str$ & CHR$(IIF(RANDOM(2) = 0, 91, 93))
    DONE
 
    status = 0
    FOR x = 1 TO LEN(str$)
        IF MID$(str$, x, 1) = "[" THEN
            INCR status
        ELSE
            DECR status
        FI
        IF status < 0 THEN BREAK
    NEXT
 
    IF status = 0 THEN
        PRINT "OK: ", str$
    ELSE
        PRINT "BAD: ", str$
    ENDIF
NEXT