Sha256: 8545f8be662d25946485e5e576d6b8370ddf5550f530efe4c5a3508b0691e47d

Contents?: true

Size: 935 Bytes

Versions: 134

Compression:

Stored size: 935 Bytes

Contents

module RomanNumerals

let numeralThresholds = [(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")]

let rec toRomanLoop remainder acc thresholds =         
    match thresholds with
        | [] -> acc
        | (threshold, numeral)::xs ->
            if threshold <= remainder then toRomanLoop (remainder - threshold) (acc + numeral) thresholds
            else toRomanLoop remainder acc xs

let roman (arabicNumeral: int) = toRomanLoop arabicNumeral "" numeralThresholds

Version data entries

134 entries across 134 versions & 1 rubygems

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