Sha256: 143a1ad027808e3189441c6705425c9e384f82977802c1e6ef9b7dd4fb031fec

Contents?: true

Size: 667 Bytes

Versions: 329

Compression:

Stored size: 667 Bytes

Contents

local function Grid(s)
  local width = 0
  local rows = {}
  for row in s:gmatch('([^\n]*)\n?') do
    table.insert(rows, row)
    width = math.max(width, #row)
  end

  return {
    at = function(x, y)
      return rows[y]:sub(x, x):match('.')
    end,
    height = #rows,
    width = width
  }
end

return function(s)
  local grid = Grid(s)
  local rows = {}
  for x = 1, grid.width do
    local row = {}
    for y = 1, grid.height do
      if grid.at(x, y) then
        while #row < y - 1 do table.insert(row, ' ') end
        table.insert(row, grid.at(x, y))
      end
    end
    table.insert(rows, table.concat(row))
  end
  return table.concat(rows, '\n')
end

Version data entries

329 entries across 329 versions & 1 rubygems

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