Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
17
Task/Balanced-brackets/XBS/balanced-brackets.xbs
Normal file
17
Task/Balanced-brackets/XBS/balanced-brackets.xbs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
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)}`);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue