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.58 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.57 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.56 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.55 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.54 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.53 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.52 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.51 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.50 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.49 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.48 tracks/elixir/exercises/scrabble-score/example.exs