Sha256: 912cfb0f0b1c78e12b942ff1ccf606adca710a27b9bb258d1ec46d45dbfbce75
Contents?: true
Size: 478 Bytes
Versions: 126
Compression:
Stored size: 478 Bytes
Contents
object ScrabbleScore { private val scoreToLetters = mapOf(1 to "AEIOULNRST", 2 to "DG", 3 to "BCMP", 4 to "FHVWY", 5 to "K", 8 to "JX", 10 to "QZ").mapValues { it.value.toCharArray() } private val letterToScore = scoreToLetters.flatMap { entry -> entry.value.map { char -> Pair(char, entry.key) } }.toMap() fun scoreLetter(c: Char) = letterToScore[c.toUpperCase()] ?: 0 fun scoreWord(word: String) = word.fold(0, { score, char -> score + scoreLetter(char) }) }
Version data entries
126 entries across 126 versions & 1 rubygems