new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
20
Task/Balanced_brackets/Lua/balanced_brackets.lua
Normal file
20
Task/Balanced_brackets/Lua/balanced_brackets.lua
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function isBalanced(s)
|
||||
--Lua pattern matching has a 'balanced' pattern that matches sets of balanced characters.
|
||||
--Any two characters can be used.
|
||||
return s:gsub('%b[]','')=='' and true or false
|
||||
end
|
||||
|
||||
function randomString()
|
||||
math.randomseed(os.time())
|
||||
math.random()math.random()math.random()math.random()
|
||||
local tokens={'[',']'}
|
||||
local result={}
|
||||
for i=1,8 do
|
||||
table.insert(result,tokens[math.random(1,2)])
|
||||
end
|
||||
return table.concat(result)
|
||||
end
|
||||
|
||||
local RS=randomString()
|
||||
print(RS)
|
||||
print(isBalanced(RS))
|
||||
Loading…
Add table
Add a link
Reference in a new issue