Balanced brackets: Difference between revisions

Content added Content deleted
No edit summary
Line 863: Line 863:


</lang>
</lang>

=={{header|Arturo}}==

<lang arturo>isBalanced [s]{
cnt 0

loop $(characters s) [c]{
if c="]" {
if $(cnt cnt-1)<0 { return false }
} {
if c="[" { cnt cnt+1 }
}
}

return cnt=0
}

loop $(range 1 9) [i]{
str $(join $(map $(range 0 2*i-1) { sample #("[" "]") }) "")
print str true
if $(isBalanced str) { print " OK" } { print " Not OK" }
}</lang>

{{out}}

<pre>[] OK
[[]] OK
[[]]][ Not OK
]]][[]]] Not OK
[[][][][[] Not OK
[[][[[[]]]]] OK
[[][[][[]][[][ Not OK
]]][[[][[]][[[]] Not OK
]]][][[[][][][]]]] Not OK</pre>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==