Balanced brackets: Difference between revisions

m
whitespace
m (moved Balanced strings to Balanced brackets: More descriptive name, as discussed on Talk page)
m (whitespace)
Line 3:
* Generate a string with <code>$N</code> opening brackets (<code>"["</code>) and <code>$N</code> closing brackets (<code>"]"</code>), in some arbitrary order.
* Determine whether the string is <em>balanced</em>; that is, whether it consists entirely of pairs of opening/closing brackets (in that order), none of which mis-nest.
<br>
 
'''Examples''':
Line 42 ⟶ 41:
"[[]][[[[]]]]" is balanced
"[[]][][]]]][[" is not balanced</pre>
 
 
=={{header|J}}==
Line 149 ⟶ 147:
 
=={{header|Python}}==
 
<lang python>>>> def gen(N):
... txt = ['['] * N + [']'] * N
Line 225 ⟶ 222:
"]][[][[][[[[]][[][]][[]]]]][" -> NOT OK
</pre>
 
=={{header|TUSCRIPT}}==
<lang tuscript>$$ MODE DATA
$$ MODE DATA
$$ SET brackets=*
[
Line 256 ⟶ 253:
status=CHECK_BRACKETS (b,brackets,a1,e1,a2,e2)
PRINT b," ",status
ENDLOOP</lang>
</lang>
Output:
<pre>
<pre style='height:30ex;overflow:scroll'>
[ ERROR
[] OK
Anonymous user