Sha256: 521ba3cbc6c01f6f5ab79db7c9cb9a4931d5367f49360756c627c6bb6cf83262

Contents?: true

Size: 588 Bytes

Versions: 131

Compression:

Stored size: 588 Bytes

Contents

defmodule Scrabble do
  def score(word) do
    word |> letters |> summarize
  end

  defp letters(word), do: word |> String.trim() |> String.downcase() |> String.codepoints()

  defp summarize(letters),
    do: Enum.reduce(letters, 0, fn letter, acc -> acc + letter_score(letter) end)

  @letter_scores [
    {"aeilnorstu", 1},
    {"dg", 2},
    {"bcmp", 3},
    {"fhvwy", 4},
    {"k", 5},
    {"jx", 8},
    {"qz", 10}
  ]

  defp letter_score(letter) do
    Enum.find_value(@letter_scores, 0, fn {letters, score} ->
      String.contains?(letters, letter) && score
    end)
  end
end

Version data entries

131 entries across 131 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.179 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.178 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.177 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.176 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.175 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.174 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.173 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.172 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.171 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.170 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.169 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.167 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.166 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.165 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.164 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.163 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.162 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.161 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.160 tracks/elixir/exercises/scrabble-score/example.exs