Sha256: f9c5e6c5909be90b6efb1dd17c632cb8e6f6ff6a6fd7e7db364b94f97eb9a340

Contents?: true

Size: 621 Bytes

Versions: 307

Compression:

Stored size: 621 Bytes

Contents

# Aliases: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000.
function to_roman(number::Integer)
    number < 1 && error("Invalid number")
    alias = [
        ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"],
        ["X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"],
        ["C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"],
        ["M", "MM", "MMM"],
    ]
    i = 1
    result = []
    while number > 0
        j = rem(number, 10)
        if j > 0
            push!(result, alias[i][j])
        end
        i += 1
        number = div(number, 10)
    end
    join(reverse(result))
end

Version data entries

307 entries across 307 versions & 1 rubygems

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