Skip to content

Instantly share code, notes, and snippets.

@cmbrown1598
Created October 6, 2017 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbrown1598/885b49855b034d7339638c3d0f44f861 to your computer and use it in GitHub Desktop.
Save cmbrown1598/885b49855b034d7339638c3d0f44f861 to your computer and use it in GitHub Desktop.
let vals = [(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 toRoman iVal =
let rec loop acc n list =
match list with
| [] -> acc
| (i, s)::xs when n >= i -> loop (acc + s) (n - i) list
| x::xs -> loop acc n xs
loop "" iVal vals
let fromRoman sVal =
let rec loop acc (str : string) list =
match list with
| [] -> acc
| (i, s)::xs when str.StartsWith(s) -> loop (acc + i) (str.Substring(s.Length)) list
| x::xs -> loop acc str xs
loop 0 sVal vals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment