src/main/scala/scrabble.scala

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Scrabble {
  def scoreLetter(x: Char) = Character.toUpperCase(x) match {
    case 'A'|'E'|'I'|'O'|'U'|'L'|'N'|'R'|'S'|'T'  => 1
    case 'D'|'G'                                  => 2
    case 'B'|'C'|'M'|'P'                          => 3
    case 'F'|'H'|'V'|'W'|'Y'                      => 4
    case 'K'                                      => 5
    case 'J'|'X'                                  => 8
    case 'Q'|'Z'                                  => 10
    case _                                        => 0
  }

  def scoreWord(word: String) = word.map(scoreLetter).sum
}

@abo64 and @bccox think this looks great

Comments


You're not logged in right now. Please login via GitHub to comment