Skip to content
Permalink
Browse files

4 is written as IV

  • Loading branch information
michaelbannister committed Jul 10, 2016
1 parent a876219 commit add596cd3699939f217b3b315038690861761470
Showing with 9 additions and 5 deletions.
  1. +7 −4 src/main/kotlin/RomanNumerals.kt
  2. +2 −1 src/test/kotlin/DecimalToRomanConverterTest.kt
@@ -3,10 +3,13 @@ private val powersOfTen = listOf(1000, 100, 10, 1)
fun Int.toRoman(): String {
val placeValues = toDecimalPlaceValues(this)
return placeValues.map {
if (it.multiplier == 5) {
(5 * it.magnitude).toRomanDigit()
} else {
it.magnitude.toRomanDigit().repeat(it.multiplier)
fun one() = it.magnitude.toRomanDigit()
fun five() = (it.magnitude * 5).toRomanDigit()
when (it.multiplier) {
in 1..3 -> one().repeat(it.multiplier)
4 -> one() + five()
5 -> five()
else -> ""
}
}.joinToString(separator = "")
}
@@ -30,7 +30,8 @@ class DecimalToRomanConverterTest {
arrayOf(5, "V"),
arrayOf(50, "L"),
arrayOf(500, "D"),
arrayOf(1555, "MDLV") // again, just checking
arrayOf(1555, "MDLV"), // again, just checking
arrayOf(4, "IV")
)

@Test

0 comments on commit add596c

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