Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,46 @@
import system'routines;
import extensions;
import extensions'text;
randomBrackets(len)
{
if (0 == len)
{
^emptyString
}
else
{
var brackets :=
Array.allocate(len).populate:(i => $91)
+
Array.allocate(len).populate:(i => $93);
brackets := brackets.randomize(len * 2);
^ brackets.summarize(new StringWriter()).toString()
}
}
extension op
{
get isBalanced()
{
var counter := new Integer(0);
self.seekEach:(ch => counter.append((ch==$91).iif(1,-1)) < 0);
^ (0 == counter)
}
}
public program()
{
for(int len := 0, len < 9, len += 1)
{
var str := randomBrackets(len);
console.printLine("""",str,"""",str.isBalanced ? " is balanced" : " is not balanced")
};
console.readChar()
}