Skip to content
Permalink
Browse files

11 is written as XI

  • Loading branch information
michaelbannister committed Jul 3, 2016
1 parent 8be1840 commit 70e47ff5ebda26249f6326dca7d455e2cca362b0
Showing with 6 additions and 7 deletions.
  1. +4 −6 src/main/kotlin/RomanNumerals.kt
  2. +2 −1 src/test/kotlin/DecimalToRomanConverterTest.kt
@@ -1,12 +1,10 @@
private val powersOfTen = listOf(1000, 100, 10, 1)

fun Int.toRoman(): String {
powersOfTen.forEach { unit ->
if (this >= unit) {
return unit.toRomanDigit().repeat(this / unit)
}
}
throw RomanNumeralException("Can't yet convert ${this} to Roman numerals")
val placeValues = toDecimalPlaceValues(this)
return placeValues.map {
it.unit.toRomanDigit().repeat(it.multiplier)
}.joinToString(separator = "")
}

fun toDecimalPlaceValues(number: Int): List<PlaceValue> {
@@ -24,7 +24,8 @@ class DecimalToRomanConverterTest {
arrayOf(100, "C"),
arrayOf(200, "CC"),
arrayOf(1000, "M"),
arrayOf(2000, "MM")
arrayOf(2000, "MM"),
arrayOf(11, "XI")
)

@Test

0 comments on commit 70e47ff

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