Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
46
Task/Balanced-brackets/Elena/balanced-brackets.elena
Normal file
46
Task/Balanced-brackets/Elena/balanced-brackets.elena
Normal 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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue