Skip to content
Permalink
Browse files

9 => IX, 90 => XC, 900 => CM

  • Loading branch information
michaelbannister committed Jul 10, 2016
1 parent 87d0c99 commit 21534a0d77356edad2a9489bbb3857d5b301648f
Showing with 4 additions and 1 deletion.
  1. +2 −0 src/main/kotlin/RomanNumerals.kt
  2. +2 −1 src/test/kotlin/DecimalToRomanConverterTest.kt
@@ -5,11 +5,13 @@ fun Int.toRoman(): String {
return placeValues.map {
fun one() = it.magnitude.toRomanDigit()
fun five() = (it.magnitude * 5).toRomanDigit()
fun ten() = (it.magnitude * 10).toRomanDigit()
when (it.multiplier) {
in 1..3 -> one().repeat(it.multiplier)
4 -> one() + five()
5 -> five()
in 6..8 -> five() + one().repeat(it.multiplier - 5)
9 -> one() + ten()
else -> ""
}
}.joinToString(separator = "")
@@ -35,7 +35,8 @@ class DecimalToRomanConverterTest {
arrayOf(444, "CDXLIV"), // again, just checking
arrayOf(666, "DCLXVI"),
arrayOf(777, "DCCLXXVII"),
arrayOf(888, "DCCCLXXXVIII")
arrayOf(888, "DCCCLXXXVIII"),
arrayOf(999, "CMXCIX")
)

@Test

0 comments on commit 21534a0

Please sign in to comment.
You can’t perform that action at this time.