Sha256: 75682d09d4cdb435c2e4f9359c4ae4e102969742691fe1b9a3c37ae328e471bb

Contents?: true

Size: 1.42 KB

Versions: 335

Compression:

Stored size: 1.42 KB

Contents

local lookup = {
  [
    ' _ ' ..
    '| |' ..
    '|_|' ..
    '   '
  ] = '0',
  [
    '   ' ..
    '  |' ..
    '  |' ..
    '   '
  ] = '1',
  [
    ' _ ' ..
    ' _|' ..
    '|_ ' ..
    '   '
  ] = '2',
  [
    ' _ ' ..
    ' _|' ..
    ' _|' ..
    '   '
  ] = '3',
  [
    '   ' ..
    '|_|' ..
    '  |' ..
    '   '
  ] = '4',
  [
    ' _ ' ..
    '|_ ' ..
    ' _|' ..
    '   '
  ] = '5',
  [
    ' _ ' ..
    '|_ ' ..
    '|_|' ..
    '   '
  ] = '6',
  [
    ' _ ' ..
    '  |' ..
    '  |' ..
    '   '
  ] = '7',
  [
    ' _ ' ..
    '|_|' ..
    '|_|' ..
    '   '
  ] = '8',
  [
    ' _ ' ..
    '|_|' ..
    ' _|' ..
    '   '
  ] = '9',
}

local row_pattern = ('[^\n]+\n'):rep(4) .. '*'

local function lines(s)
  local lines = {}
  for line in s:gmatch('[^\n]+') do
    assert(#line % 3 == 0)
    table.insert(lines, line)
  end
  return lines
end

local function parse(row)
  local result = ''
  local lines = lines(row)
  assert(#lines[1] == #lines[2] and
         #lines[2] == #lines[3] and
         #lines[3] == #lines[4])
  for i = 1, #lines[1], 3 do
    local character = ''
    for line = 1, 4 do
      character = character .. lines[line]:sub(i, i + 2)
    end
    result = result .. (lookup[character] or '?')
  end
  return result
end

return {
  convert = function(s)
    local results = {}
    for row in s:gmatch(row_pattern) do
      table.insert(results, parse(row))
    end
    return table.concat(results, ',')
  end
}

Version data entries

335 entries across 335 versions & 1 rubygems

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