Sha256: d37761428bb654495a940c222379506138fb35ddfc2183fbf96a8f2416d2038b
Contents?: true
Size: 502 Bytes
Versions: 396
Compression:
Stored size: 502 Bytes
Contents
local opening_bracket = { ['('] = true, ['['] = true, ['{'] = true } local closing_bracket = { [')'] = '(', [']'] = '[', ['}'] = '{' } return { valid = function(s) local history = {} for c in s:gmatch('.') do if opening_bracket[c] then table.insert(history, c) elseif closing_bracket[c] then if history[#history] ~= closing_bracket[c] then return false end table.remove(history, #history) end end return #history == 0 end }
Version data entries
396 entries across 396 versions & 1 rubygems