Created
February 16, 2010 16:06
-
-
Save hibri/305621 to your computer and use it in GitHub Desktop.
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
#light | |
module Roman | |
open System | |
type RomanNumber ={ | |
num:string; | |
decimal_num:int; | |
left_bound:int; | |
right_bound:int; | |
} | |
let is_left_of(x, n:RomanNumber) = | |
(x >= n.left_bound && x < n.decimal_num) | |
let is_right_of(x, n:RomanNumber) = | |
(x >= n.decimal_num && x < n.right_bound) | |
let nums = [ | |
{ num="X"; decimal_num = 10; left_bound = 9; right_bound = 18;}; | |
{ num="L"; decimal_num = 50; left_bound = 40; right_bound = 90;}; | |
{ num="C"; decimal_num = 100; left_bound = 90; right_bound = 400;} | |
] | |
let rec convert x = | |
for i in nums do | |
if(is_left_of(x, i)) then | |
convert(i.decimal_num-x) + i.num | |
elif(is_right_of(x, i)) then | |
i.num + convert(x-i.decimal_num) | |
else | |
match Math.Abs((int)x) with | |
| 0 -> "" | |
| 1 -> "I" | |
| 2 -> "II" | |
| 3-> "III" | |
| 4 -> "IV" | |
| 5 -> "V" | |
| 6 -> "VI" | |
| 7 -> "VII" | |
| 8 -> "VIII" | |
| x -> "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment