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.98 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.97 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.96 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.95 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.94 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.93 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.92 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.91 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.90 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.89 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.88 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.87 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.86 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.85 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.84 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.83 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.82 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.81 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.80 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.79 tracks/elixir/exercises/scrabble-score/example.exs