16 lines
370 B
Plaintext
16 lines
370 B
Plaintext
(include "string")
|
|
|
|
(defn bool balanced (std::string s)
|
|
(def bal 0)
|
|
(foreach c s
|
|
(if (== c #\[) (++ bal)
|
|
(if (== c #\]) (-- bal)))
|
|
(if (< bal 0) (return false)))
|
|
(return (== bal 0)))
|
|
|
|
(main
|
|
(decl std::string (at tests) |{"", "[]", "[][]", "[[][]]", "][", "][][", "[]][[]"}|)
|
|
(pr std::boolalpha)
|
|
(foreach x tests
|
|
(prn x "\t" (balanced x))))
|