Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
34
Task/Balanced-brackets/Ballerina/balanced-brackets.ballerina
Normal file
34
Task/Balanced-brackets/Ballerina/balanced-brackets.ballerina
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import ballerina/io;
|
||||
import ballerina/random;
|
||||
|
||||
function isBalanced(string s) returns boolean {
|
||||
if s == "" { return true; }
|
||||
int countLeft = 0; // number of left brackets so far unmatched
|
||||
foreach var c in s {
|
||||
if c == "[" {
|
||||
countLeft += 1;
|
||||
} else if countLeft > 0 {
|
||||
countLeft -= 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return countLeft == 0;
|
||||
}
|
||||
|
||||
public function main() {
|
||||
io:println("Checking examples in task description:");
|
||||
var brackets = ["", "[]", "][", "[][]", "][][", "[[][]]", "[]][[]"];
|
||||
foreach string b in brackets {
|
||||
io:print((b != "") ? b : "(empty)");
|
||||
io:println("\t ", isBalanced(b) ? "OK" : "NOT OK");
|
||||
}
|
||||
io:println("\nChecking 7 random strings of brackets of length 8:");
|
||||
foreach int i in 1...7 {
|
||||
string s = "";
|
||||
foreach int j in 1...8 {
|
||||
s += random:createIntInRange(0, 2) == 0 ? "[" : "]";
|
||||
}
|
||||
io:println(s, " ", isBalanced(s) ? "OK" : "NOT OK");
|
||||
}
|
||||
}
|
||||
1
Task/Balanced-brackets/Excel/balanced-brackets-3.excel
Normal file
1
Task/Balanced-brackets/Excel/balanced-brackets-3.excel
Normal file
|
|
@ -0,0 +1 @@
|
|||
=REDUCE(A2, SEQUENCE(MAX(1, LEN(A2))), LAMBDA(a, _, SUBSTITUTE(a, "[]", ))) = ""
|
||||
1
Task/Balanced-brackets/Excel/balanced-brackets-4.excel
Normal file
1
Task/Balanced-brackets/Excel/balanced-brackets-4.excel
Normal file
|
|
@ -0,0 +1 @@
|
|||
=REDUCE(REGEXREPLACE(A2, "[^\[\]]", ), SEQUENCE(MAX(1, LEN(A2))), LAMBDA(a, _, SUBSTITUTE(a, "[]", ))) = ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue