Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- convert(1999)
- def convert(num: Int): Unit = {
- val l = toList(num)
- toRomanNumerals(l)
- println()
- println()
- }
- def toRomanNumerals(nums : List[Int]): Unit ={
- if(nums.nonEmpty){
- print(toRomanNumeral(nums.length-1 , nums.head))
- toRomanNumerals(nums.tail)
- }
- }
- def toRomanNumeral(tens: Int, digit: Int): String = {
- val (bot, middle, top) =
- if (tens == 0)
- ("I", "V", "X")
- else if (tens == 1)
- ("X", "L", "C")
- else if(tens == 2)
- ("C", "D", "M")
- else if(tens == 3)
- ("M", "?", "??")
- digit match{
- case 1 => s"$bot"
- case 2 => s"$bot$bot"
- case 3 => s"$bot$bot$bot"
- case 4 => s"$bot$middle"
- case 5 => s"$middle"
- case 6 => s"$middle$bot"
- case 7 => s"$middle$bot$bot"
- case 8 => s"$middle$bot$bot$bot"
- case 9 => s"$bot$top"
- case _ => ""
- }
- }
- def toList(num: Int): List[Int] = {
- num.toString.map(_.toString.toInt).toList
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement