Sha256: fddd4245c88f264300468bd0369cef26c560eb57a2d69fba13446f96870b55ac

Contents?: true

Size: 619 Bytes

Versions: 37

Compression:

Stored size: 619 Bytes

Contents

type
    Numeral = tuple[number: int, roman: string]
    NumeralArray = array[13, Numeral]

let
    numeral_mapping: NumeralArray = [
        (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")
    ]


proc numeral*(number: int): string =
    var s = ""
    var n = number
    for numeral in numeral_mapping:
        while n >= numeral.number:
            s = s & numeral.roman
            n = n - numeral.number
    return s

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
trackler-2.2.1.172 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.171 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.170 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.169 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.167 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.166 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.165 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.164 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.163 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.162 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.161 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.160 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.159 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.158 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.157 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.156 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.155 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.154 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.153 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.152 tracks/nim/exercises/roman-numerals/example.nim