Anonymous user
Validate International Securities Identification Number: Difference between revisions
Validate International Securities Identification Number (view source)
Revision as of 22:47, 28 March 2017
, 7 years ago→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details
No edit summary |
(→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details) |
||
Line 766:
// validate checksum
val sb = StringBuilder()
for (c in s) {
when (c) {
in '0'..'9' -> sb.append(c)
in 'A'..'Z' -> sb.append((c.toInt() - 55).toString().padStart(2, '0'))
}
}
return luhn(sb.toString())
}
private fun luhn(s: String): Boolean {
fun sumDigits(n
val
val s1 = t.filterIndexed { i, _ -> i % 2 == 0 }.sumBy { it - '0' }
val s2 = t.filterIndexed { i, _ -> i % 2 == 1 }.map { sumDigits((it - '0') * 2) }.sum()
Line 784 ⟶ 785:
fun main(args: Array<String>) {
val isins = arrayOf(
"AU0000XVGZA3", "AU0000VXGZA3", "FR0000988040"
for (isin in isins) println("$isin\t -> ${if (Isin.isValid(isin)) "valid" else "not valid"}")▼
)
for (isin in isins) {
}
}</lang>
|