From bd6b6dd5c711748abc54ffb91e6a2bb2869613ca Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Thu, 7 Aug 2025 06:51:53 +0000 Subject: [PATCH] [Sync Iteration] elixir/scrabble-score/1 --- .../elixir/scrabble-score/1/lib/scrabble.ex | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 solutions/elixir/scrabble-score/1/lib/scrabble.ex diff --git a/solutions/elixir/scrabble-score/1/lib/scrabble.ex b/solutions/elixir/scrabble-score/1/lib/scrabble.ex new file mode 100644 index 0000000..9c8a75d --- /dev/null +++ b/solutions/elixir/scrabble-score/1/lib/scrabble.ex @@ -0,0 +1,40 @@ +defmodule Scrabble do + @en_scores %{ + "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 + } + @doc """ + Calculate the scrabble score for the word. + """ + @spec score(String.t()) :: non_neg_integer + def score(word) do + word + |> String.upcase() + |> String.graphemes() + |> Enum.reduce(0, &(Map.get(@en_scores, &1, 0) + &2)) + end +end