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.151 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.150 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.149 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.148 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.147 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.146 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.145 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.144 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.143 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.142 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.141 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.140 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.139 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.138 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.137 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.136 tracks/nim/exercises/roman-numerals/example.nim
trackler-2.2.1.135 tracks/nim/exercises/roman-numerals/example.nim