Skip to content

Instantly share code, notes, and snippets.

@radar
Created May 31, 2017 01:03
Show Gist options
  • Save radar/3181273e9f1f8e9db68d1bac953198f3 to your computer and use it in GitHub Desktop.
Save radar/3181273e9f1f8e9db68d1bac953198f3 to your computer and use it in GitHub Desktop.
defmodule Scrabble do
@letters %{
"A" => 1, "B" => 3, "C" => 3, "D" => 2,
"E" => 1, "F" => 4, "G" => 2, "H" => 4,
"I" => 1, "J" => 8, "K" => 5, "L" => 1,
"M" => 3, "N" => 1, "O" => 1, "P" => 3,
"Q" => 10, "R" => 1, "S" => 1, "T" => 1,
"U" => 1, "V" => 4, "W" => 4, "X" => 8,
"Y" => 4, "Z" => 10
}
def score(nil), do: 0
def score(""), do: 0
def score(word) do
word
|> String.upcase
|> String.split("")
|> Enum.reject(&(&1 == ""))
|> Enum.map(&(@letters[&1]))
|> Enum.sum
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment