Bə mətni dəvarde

Modul:RomanNumber

Сe Vikipedija

Documentation for this module may be created at Modul:RomanNumber/doc

local m = {}
 
local digit_1000 = {[0] = "", [1] = "M", [2] = "MM", [3] = "MMM"}
local digit_100  = {[0] = "", [1] = "C", [2] = "CC", [3] = "CCC", [4] = "CD", [5] = "D", [6] = "DC", [7] = "DCC", [8] = "DCCC", [9] = "CM"}
local digit_10   = {[0] = "", [1] = "X", [2] = "XX", [3] = "XXX", [4] = "XL", [5] = "L", [6] = "LX", [7] = "LXX", [8] = "LXXC", [9] = "XC"}
local digit_1    = {[0] = "", [1] = "I", [2] = "II", [3] = "III", [4] = "IV", [5] = "V", [6] = "VI", [7] = "VII", [8] = "VIII", [9] = "IX"}
 
function m.toRomanNumber(n_number)
    assert((n_number >= 1) and (n_number <= 3999))
    local n_1000, n_100, n_10, n_1
    n_1000    = math.floor(n_number/1000)
    n_number  = n_number - 1000*n_1000
    n_100     = math.floor(n_number/100)
    n_number  = n_number - 100*n_100
    n_10      = math.floor(n_number/10)
    n_1       = n_number - 10*n_10
    return digit_1000[n_1000]..digit_100[n_100]..digit_10[n_10]..digit_1[n_1]
end;
 
function m.roman(frame)
    return m.toRomanNumber(tonumber(frame.args[1]))
end
 
return m