23 lines
320 B
Text
23 lines
320 B
Text
isBalanced: function [s][
|
|
cnt: 0
|
|
|
|
loop split s [ch][
|
|
switch ch="]" [
|
|
cnt: cnt-1
|
|
if cnt<0 -> return false
|
|
][
|
|
if ch="[" -> cnt: cnt+1
|
|
]
|
|
]
|
|
|
|
cnt=0
|
|
]
|
|
|
|
loop 1..10 'i [
|
|
str: join map 0..(2*i)-1 [x][ sample ["[" "]"]]
|
|
|
|
prints str
|
|
|
|
switch isBalanced str -> print " OK"
|
|
-> print " Not OK"
|
|
]
|