Sha256: 87a77e3fe4276f21d86d6c55366197a95b20541170a362bb4a7da0e41a923234

Contents?: true

Size: 708 Bytes

Versions: 396

Compression:

Stored size: 708 Bytes

Contents

local mappings = {
  { value = 1000, numeral = 'M' },
  { value = 900, numeral = 'CM' },
  { value = 500, numeral = 'D' },
  { value = 400, numeral = 'CD' },
  { value = 100, numeral = 'C' },
  { value = 90, numeral = 'XC' },
  { value = 50, numeral = 'L' },
  { value = 40, numeral = 'XL' },
  { value = 10, numeral = 'X' },
  { value = 9, numeral = 'IX' },
  { value = 5, numeral = 'V' },
  { value = 4, numeral = 'IV' },
  { value = 1, numeral = 'I' },
}

return {
  to_roman = function(n)
    local result = ''
    for _, mapping in ipairs(mappings) do
      while n >= mapping.value do
        result = result .. mapping.numeral
        n = n - mapping.value
      end
    end
    return result
  end
}

Version data entries

396 entries across 396 versions & 1 rubygems

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