Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Created March 5, 2023 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvilarino/fcfc41ae75015a5921995dea57de8dc4 to your computer and use it in GitHub Desktop.
Save fvilarino/fcfc41ae75015a5921995dea57de8dc4 to your computer and use it in GitHub Desktop.
Ticker - Alphabet
private object AlphabetMapper {
// 1
private val Alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789•".toList()
val size: Int = Alphabet.size
// 2
fun getLetterAt(index: Int): Char = Alphabet[index % size]
// 3
fun getIndexOf(letter: Char): Int {
val index = Alphabet.indexOf(letter.uppercaseChar())
return if (index < 0) Alphabet.lastIndex else index
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment