Skip to content

Instantly share code, notes, and snippets.

@sixthgear
Created January 15, 2015 21:56
Show Gist options
  • Save sixthgear/c4c490e1d74f23146fcf to your computer and use it in GitHub Desktop.
Save sixthgear/c4c490e1d74f23146fcf to your computer and use it in GitHub Desktop.
main = getLine >>= \d -> putStrLn (decToRoman (read d :: Integer)) >> main
decToRoman :: Integer -> String
decToRoman dec
| dec >= 1000 = "M" ++ decToRoman(dec - 1000)
| dec >= 900 = "CM" ++ decToRoman(dec - 900)
| dec >= 500 = "D" ++ decToRoman(dec - 500)
| dec >= 400 = "CD" ++ decToRoman(dec - 400)
| dec >= 100 = "C" ++ decToRoman(dec - 100)
| dec >= 90 = "XC" ++ decToRoman(dec - 90)
| dec >= 50 = "L" ++ decToRoman(dec - 50)
| dec >= 40 = "XL" ++ decToRoman(dec - 40)
| dec >= 10 = "X" ++ decToRoman(dec - 10)
| dec >= 9 = "IX" ++ decToRoman(dec - 9)
| dec >= 5 = "V" ++ decToRoman(dec - 5)
| dec >= 4 = "IV" ++ decToRoman(dec - 4)
| dec >= 1 = "I" ++ decToRoman(dec - 1)
| otherwise = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment