new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
|
|
@ -0,0 +1,17 @@
|
|||
> coffee balanced.coffee
|
||||
[[[[ false
|
||||
[[[] false
|
||||
[[][ false
|
||||
[[]] true
|
||||
[][[ false
|
||||
[][] true
|
||||
[]][ false
|
||||
[]]] false
|
||||
][[[ false
|
||||
][[] false
|
||||
][][ false
|
||||
][]] false
|
||||
]][[ false
|
||||
]][] false
|
||||
]]][ false
|
||||
]]]] false
|
||||
15
Task/Balanced_brackets/CoffeeScript/balanced_brackets.coffee
Normal file
15
Task/Balanced_brackets/CoffeeScript/balanced_brackets.coffee
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
isBalanced = (brackets) ->
|
||||
openCount = 0
|
||||
for bracket in brackets
|
||||
openCount += if bracket is '[' then 1 else -1
|
||||
return false if openCount < 0
|
||||
openCount is 0
|
||||
|
||||
bracketsCombinations = (n) ->
|
||||
for i in [0...Math.pow 2, n]
|
||||
str = i.toString 2
|
||||
str = '0' + str while str.length < n
|
||||
str.replace(/0/g, '[').replace(/1/g, ']')
|
||||
|
||||
for brackets in bracketsCombinations 4
|
||||
console.log brackets, isBalanced brackets
|
||||
Loading…
Add table
Add a link
Reference in a new issue