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.78 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.77 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.76 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.75 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.74 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.73 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.72 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.71 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.70 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.69 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.68 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.67 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.66 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.65 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.64 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.63 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.62 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.61 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.60 tracks/elixir/exercises/scrabble-score/example.exs
trackler-2.2.1.59 tracks/elixir/exercises/scrabble-score/example.exs