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



const Chars:[string] = ["[","]"];
func GenerateString(Amount:number=4):string{
	set Result:string = "";
	<|(*1..Amount)=>Result+=Chars[math.random(0,?Chars-1)];
	send Result;
}
 
func IsBalanced(String:string):boolean{
	set Pairs:number = 0;
	<|(*(0..(?String-1)))=>(String::at(_)=="[")?(Pairs<0)?=>send false,Pairs++,=>Pairs--;
	send (Opens==Closes)&(Pairs==0);
}
 
repeat 10 {
	set s = GenerateString(math.random(2,4)*2);
	log(`{s}: {IsBalanced(s)}`);
}