Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Balanced-brackets/Brat/balanced-brackets.brat
Normal file
31
Task/Balanced-brackets/Brat/balanced-brackets.brat
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
string.prototype.balanced? = {
|
||||
brackets = []
|
||||
balanced = true
|
||||
|
||||
my.dice.each_while { c |
|
||||
true? c == "["
|
||||
{ brackets << c }
|
||||
{ true? c == "]"
|
||||
{ last = brackets.pop
|
||||
false? last == "["
|
||||
{ balanced = false }
|
||||
}
|
||||
}
|
||||
|
||||
balanced
|
||||
}
|
||||
|
||||
true? brackets.empty?
|
||||
{ balanced }
|
||||
{ false }
|
||||
}
|
||||
|
||||
generate_brackets = { n | (n.of("[") + n.of("]")).shuffle.join }
|
||||
|
||||
1.to 10 { n |
|
||||
test = generate_brackets n
|
||||
|
||||
true? test.balanced?
|
||||
{ p "#{test} is balanced" }
|
||||
{ p "#{test} is not balanced" }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue