Skip to content
Permalink
Browse files

Rename PlaceValue property 'unit' to 'magnitude'

  • Loading branch information
michaelbannister committed Jul 9, 2016
1 parent a26613a commit bdc01e4f757af17ee15ddeb390104170b252a98c
Showing with 5 additions and 5 deletions.
  1. +5 −5 src/main/kotlin/RomanNumerals.kt
@@ -3,7 +3,7 @@ private val powersOfTen = listOf(1000, 100, 10, 1)
fun Int.toRoman(): String {
val placeValues = toDecimalPlaceValues(this)
return placeValues.map {
it.unit.toRomanDigit().repeat(it.multiplier)
it.magnitude.toRomanDigit().repeat(it.multiplier)
}.joinToString(separator = "")
}

@@ -13,11 +13,11 @@ fun toDecimalPlaceValues(number: Int): List<PlaceValue> {
}
val largestPowerNeeded = powersOfTen.find { number >= it } ?: 1
if (largestPowerNeeded == 1) {
return listOf(PlaceValue(number, 1))
return listOf(PlaceValue(multiplier = number, magnitude = 1))
} else {
val multiplier = number / largestPowerNeeded
val remainder = number % largestPowerNeeded
return listOf(PlaceValue(multiplier, largestPowerNeeded)) + toDecimalPlaceValues(remainder)
return listOf(PlaceValue(multiplier, magnitude = largestPowerNeeded)) + toDecimalPlaceValues(remainder)
}
}

@@ -31,6 +31,6 @@ private fun Int.toRomanDigit(): String = when(this) {

internal class RomanNumeralException(message: String) : RuntimeException(message)

data class PlaceValue(val multiplier: Int, val unit: Int) {
override fun toString(): String = "$multiplier*$unit"
data class PlaceValue(val multiplier: Int, val magnitude: Int) {
override fun toString(): String = "$multiplier*$magnitude"
}

0 comments on commit bdc01e4

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