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

local function get_occurrence_count(s, chr)
    return select(2, s:gsub(chr, ""))
end



function intToRoman(num)
    local roman = ""
    while num > 0 do
        for index,v in pairs(numberMap)do 
            local romanChar = v[2]
            local int = v[1]
            while num >= int do
                roman = roman..romanChar
                num = num - int
            end
        end
    end
    if num > 10000 then
      local amount =  get_occurrence_count(roman, "M")
      roman = "M*"..amount.." "..roman
    end
    return roman
end
local num = io.read()
num = tonumber(num)
print("Roman: "..intToRoman(num))













Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: