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.78 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.77 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.76 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.75 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.74 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.73 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.72 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.71 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.70 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.69 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.68 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.67 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.66 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.65 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.64 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.63 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.62 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.61 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.60 tracks/fsharp/exercises/roman-numerals/Example.fs
trackler-2.2.1.59 tracks/fsharp/exercises/roman-numerals/Example.fs