2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,36 @@
val romanNumerals = mapOf(
1000 to "M",
900 to "CM",
500 to "D",
400 to "CD",
100 to "C",
90 to "XC",
50 to "L",
40 to "XL",
10 to "X",
9 to "IX",
5 to "V",
4 to "IV",
1 to "I"
)
fun encode(number: Int): String? {
if (number > 5000 || number < 1) {
return null
}
var num = number
val buffer = StringBuffer()
for ((multiple, numeral) in romanNumerals) {
while (num >= multiple) {
num -= multiple
buffer.append(numeral)
}
}
return buffer.toString()
}
fun main(args: Array<String>) {
println(encode(1990))
println(encode(1666))
println(encode(2008))
}