25 lines
555 B
Plaintext
25 lines
555 B
Plaintext
(import std.List)
|
|
|
|
(let gen_string (fun (length) {
|
|
(mut output "")
|
|
(while (< (len output) length) {
|
|
(set output (+ output (@ "[]" (random 0 1)))) })
|
|
output }))
|
|
|
|
(let balanced? (fun (str) {
|
|
(mut i 0)
|
|
(=
|
|
(len str)
|
|
(len
|
|
(list:takeWhile str (fun (char) {
|
|
(if (= "[" char)
|
|
(set i (+ i 1))
|
|
(set i (- i 1)))
|
|
(>= i 0) }))))}))
|
|
|
|
(list:forEach
|
|
(list:iota 0 5)
|
|
(fun (_) {
|
|
(let str (gen_string (random 2 8)))
|
|
(print (string:format "{:<8}: {:^6}" str (if (balanced? str) "OK" "NOT OK"))) }))
|