Balanced brackets: Difference between revisions
Content added Content deleted
(→Tcl: Added implementation) |
|||
Line 14: | Line 14: | ||
void main() { |
void main() { |
||
foreach (s; ",[],[][],[[][]],][,][][,[]][[]".split(",")) |
foreach (s; ",[],[][],[[][]],][,][][,[]][[]".split(",")) |
||
writefln("% |
writefln("%-8s is%s balanced", '"' ~ s ~ '"', |
||
s.balancedParens('[', ']') ? "" : " not"); |
s.balancedParens('[', ']') ? "" : " not"); |
||
}</lang> |
}</lang> |
||
Output: |
Output: |
||
<pre> is balanced |
<pre>"" is balanced |
||
[] is balanced |
"[]" is balanced |
||
[][] is balanced |
"[][]" is balanced |
||
[[][]] is balanced |
"[[][]]" is balanced |
||
][ is not balanced |
"][" is not balanced |
||
][][ is not balanced |
"][][" is not balanced |
||
[]][[] is not balanced</pre> |
"[]][[]" is not balanced</pre> |
||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
<lang perl6>sub balanced($s) { |
<lang perl6>sub balanced($s) { |