SEDOLs: Difference between revisions
→{{header|Kotlin}}: Make Kotlin solution more succinct using modern library features
(Added Easylang) |
(→{{header|Kotlin}}: Make Kotlin solution more succinct using modern library features) |
||
Line 2,368:
=={{header|Kotlin}}==
<syntaxhighlight lang="
val validChars = (('0'..'9') + ('A'..'Z')).toSet() - "AEIOU".toSet()
▲val weights = listOf(1, 3, 1, 7, 3, 9, 1)
fun sedol7(sedol6: String): String {
if (sedol6.length != 6
throw IllegalArgumentException("Argument string contains an invalid character")
val sum = sedol6.map { it.digitToInt(36) }.zip(weights, Int::times).sum()
val check =
▲ else -> throw IllegalArgumentException("Argument string contains an invalid character")
}▼
▲ return sedol6 + (check + 48).toChar()
}
fun main(
val sedol6s = listOf(
"557910", "B0YBKR", "585284", "B0YBKT", "B00030"
for (sedol6 in sedol6s) println("$sedol6 -> ${sedol7(sedol6)}")▼
}</syntaxhighlight>▼
for (sedol6 in sedol6s)
}
{{out}}
|