3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
6 # Task: Balanced brackets
7 # SEE: <http://rosettacode.org/wiki/Balanced_brackets>
8 module balanced_brackets
10 # Are `[` and `]` balanced?
11 # Other characters are ignored.
13 # assert is_balanced("[][[]]")
14 # assert is_balanced("")
15 # assert not is_balanced("[[]")
16 # assert not is_balanced("][][")
17 fun is_balanced
(s
: String): Bool
25 if l
< 0 then return false
32 if args
.not_empty
then n
= args
.first
.to_i
35 var a
= (['[', ']'] * n
)
38 if is_balanced
(b
) then print
"{b} is well-balanced" else print
"{b} is not well-balanced"