Balanced brackets: Difference between revisions
Content added Content deleted
(→{{header|Nim}}: Mercury) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 16: | Line 16: | ||
[]][[] NOT OK |
[]][[] NOT OK |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F gen(n) |
|||
A txt = [‘[’, ‘]’] * n |
|||
random:shuffle(txt) |
|||
R txt.join(‘’) |
|||
F is_balanced(s) |
|||
A nesting_level = 0 |
|||
L(c) s |
|||
S c |
|||
‘[’ |
|||
nesting_level++ |
|||
‘]’ |
|||
I --nesting_level < 0 |
|||
R 0B |
|||
R 1B |
|||
L(n) 0..9 |
|||
A s = gen(n) |
|||
print(s‘’(‘ ’ * (20 - s.len))‘is ’(I is_balanced(s) {‘balanced’} E ‘not balanced’))</lang> |
|||
{{out}} |
|||
<pre> |
|||
is balanced |
|||
[] is balanced |
|||
[]][ is not balanced |
|||
][[[]] is not balanced |
|||
[]][][[] is not balanced |
|||
][[][[[]]] is not balanced |
|||
[[]]][[][]][ is not balanced |
|||
[[]][[]]]][[][ is not balanced |
|||
[]]][[[[]]]]][[[ is not balanced |
|||
]][]]][[[[[]][]][[ is not balanced |
|||
</pre> |
|||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |