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

Version Path
trackler-2.2.1.180 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.179 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.178 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.177 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.176 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.175 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.174 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.173 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.172 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.171 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.170 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.169 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.167 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.166 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.165 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.164 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.163 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.162 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.161 tracks/lua/exercises/bracket-push/example.lua
trackler-2.2.1.160 tracks/lua/exercises/bracket-push/example.lua