Created
November 10, 2017 21:23
-
-
Save Ummon/7cffb6264249ede0b77f93e98163c089 to your computer and use it in GitHub Desktop.
Transform an integer to a roman numeral
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fsharpi | |
let elements = [ "M", 1000; "CM", 900; "D", 500; "CD", 400; "C", 100; "XC", 90; "L", 50; "XL", 40; "X", 10; "IX", 9; "V", 5; "IV", 4; "I", 1 ] | |
let rec toRomanNumber (v : int) : string = | |
if v >= 1 then | |
let e, v' = elements |> List.find (snd >> (>=) v) | |
e + toRomanNumber (v - v') | |
else | |
"" | |
for i = 1 to 100 do | |
printfn "%i: %s" i (toRomanNumber i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment