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.159 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.158 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.157 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.156 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.155 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.154 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.153 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.152 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.151 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.150 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.149 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.148 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.147 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.146 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.145 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.144 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.143 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.142 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.141 tracks/lua/exercises/ocr-numbers/example.lua
trackler-2.2.1.140 tracks/lua/exercises/ocr-numbers/example.lua