Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,33 +1,33 @@
|
|||
import Nanoquery.Util
|
||||
|
||||
def gen(N)
|
||||
txt = {"[", "]"} * N
|
||||
txt = new(Random).shuffle(txt)
|
||||
return "".join("", txt)
|
||||
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
|
||||
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
|
||||
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