Guest User

Untitled

a guest
Nov 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. class RomanNumeral {
  2. def toRomanNumerals( number: Int) : String = {
  3. toRomanNumerals( number, List( ("M", 1000),("CM", 900), ("D", 500), ("CD", 400), ("C", 100), ("XC", 90),
  4. ("L", 50), ("XL",40), ("X", 10), ("IX", 9), ("V", 5), ("IV", 4), ("I", 1) ))
  5. }
  6.  
  7. private def toRomanNumerals( number: Int, digits: List[(String, Int)] ) : String = digits match {
  8. case Nil => ""
  9. case h :: t => h._1 * ( number / h._2 ) + toRomanNumerals( number % h._2, t )
  10. }
  11. }
Add Comment
Please, Sign In to add comment