therealbluepandabear
03/07/2021, 3:58 AMfun charToNumber(input: Char): Int {
val numbersToLetters = listOf('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
return numbersToLetters.indexOf(input.toUpperCase()) + 1
}
ephemient
03/07/2021, 4:00 AM('A'..'Z').indexOf(input.toUpperCase())
rnett
03/07/2021, 4:15 AM'A'.toInt() - 64
(for 1 indexed) See http://www.asciitable.com/ephemient
03/07/2021, 4:18 AMephemient
03/07/2021, 4:18 AMephemient
03/07/2021, 4:19 AMwhen (input) {
'A'..'Z' -> input.toInt() - 'A'.toInt()
'a'..'z' -> input.toInt() - 'a'.toInt()
else -> -1
}
ilya.gorbunov
03/07/2021, 4:22 AMtoInt
conversion is not necessary, just input - 'A'
will do.ephemient
03/07/2021, 4:24 AM