-
-
Save hackling/7333eeceb735233ced85bc0126609435 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Scrabble do | |
def score(nil), do: 0 | |
def score(""), do: 0 | |
def score("A"), do: 1 | |
def score("B"), do: 3 | |
def score("C"), do: 3 | |
def score("D"), do: 2 | |
def score("E"), do: 1 | |
def score("F"), do: 4 | |
def score("G"), do: 2 | |
def score("H"), do: 4 | |
def score("I"), do: 1 | |
def score("J"), do: 8 | |
def score("K"), do: 5 | |
def score("L"), do: 1 | |
def score("M"), do: 3 | |
def score("N"), do: 1 | |
def score("O"), do: 1 | |
def score("P"), do: 3 | |
def score("Q"), do: 10 | |
def score("R"), do: 1 | |
def score("S"), do: 1 | |
def score("T"), do: 1 | |
def score("U"), do: 1 | |
def score("V"), do: 4 | |
def score("W"), do: 4 | |
def score("X"), do: 8 | |
def score("Y"), do: 4 | |
def score("Z"), do: 10 | |
def score(word) do | |
word | |
|> String.upcase | |
|> String.split("") | |
|> Enum.map(&(score(&1))) | |
|> Enum.sum | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment