Sha256: b64dc32362391799d82b155d0340a7603bc268d5602b4d77d9c3441362655afd
Contents?: true
Size: 656 Bytes
Versions: 163
Compression:
Stored size: 656 Bytes
Contents
import scala.annotation.tailrec import scala.collection.immutable.ListMap object RomanNumeral { private def numeralValues = ListMap( 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" ) def toNumerals(n: Int) = fromNumber(n, "") @tailrec private def fromNumber(n: Int, numerals: String): String = { numeralValues.find(_._1 <= n) match { case Some((threshold, numeral)) => fromNumber(n - threshold, numerals + numeral) case None => numerals } } }
Version data entries
163 entries across 163 versions & 1 rubygems