Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
33
Task/Balanced-brackets/Nanoquery/balanced-brackets.nanoquery
Normal file
33
Task/Balanced-brackets/Nanoquery/balanced-brackets.nanoquery
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import Nanoquery.Util
|
||||
|
||||
def gen(N)
|
||||
txt = {"[", "]"} * N
|
||||
txt = new(Random).shuffle(txt)
|
||||
return "".join("", txt)
|
||||
end
|
||||
|
||||
def balanced(txt)
|
||||
braced = 0
|
||||
for ch in txt
|
||||
if ch = "["
|
||||
braced += 1
|
||||
else if ch = "]"
|
||||
braced -= 1
|
||||
end
|
||||
|
||||
if braced < 0
|
||||
return false
|
||||
end
|
||||
end
|
||||
return braced = 0
|
||||
end
|
||||
|
||||
// unlike Python, the range function is inclusive in Nanoquery
|
||||
for N in range(1, 10)
|
||||
txt = gen(N)
|
||||
if balanced(txt)
|
||||
println format("%-22s is balanced", txt)
|
||||
else
|
||||
println format("%-22s is not balanced", txt)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue