View Source Hangman.Dictionary (Hangman Dictionary v0.1.48)

Dictionary for the Hangman Game. Returns a random word.

Based on the course Elixir for Programmers by Dave Thomas.

Summary

Types

A word with letters from a to z

Functions

Returns the longest words in the dictionary (longer than floor). Note that word lengths will be enclosed in parentheses after each word.

Returns a random word from the dictionary.

Refreshes the dictionary.

Returns all the repeated words in the dictionary. Note that repetition counts will be enclosed in parentheses after each word.

Returns the shortest words in the dictionary (shorter than ceil).

Returns the number of words in the dictionary.

Returns all the words in the dictionary of length word_length.

Returns all the words in the dictionary starting with prefix.

Types

word()

@type word() :: String.t()

A word with letters from a to z

Functions

longest_words(floor \\ 13)

@spec longest_words(non_neg_integer()) :: [String.t()]

Returns the longest words in the dictionary (longer than floor). Note that word lengths will be enclosed in parentheses after each word.

In iex, you may want to run:

IEx.configure(inspect: [limit: :infinity])

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.longest_words() |> Enum.take(9)
[
  "telecommunications (18)",
  "characterization (16)",
  "responsibilities (16)",
  "sublimedirectory (16)",
  "characteristics (15)",
  "confidentiality (15)",
  "congratulations (15)",
  "instrumentation (15)",
  "internationally (15)"
]

iex> alias Hangman.Dictionary
iex> Dictionary.longest_words(14)
[
  "telecommunications (18)",
  "characterization (16)",
  "responsibilities (16)",
  "sublimedirectory (16)",
  "characteristics (15)",
  "confidentiality (15)",
  "congratulations (15)",
  "instrumentation (15)",
  "internationally (15)",
  "pharmaceuticals (15)",
  "recommendations (15)",
  "representations (15)",
  "representatives (15)",
  "troubleshooting (15)"
]

random_word()

@spec random_word() :: word()

Returns a random word from the dictionary.

Examples

iex> alias Hangman.Dictionary
iex> for _ <- 0..99, uniq: true do
iex>   Dictionary.random_word() =~ ~r/^[a-z]+$/
iex> end
[true]

iex> alias Hangman.Dictionary.WordsAgent
iex> words = Agent.get(WordsAgent, & &1)
iex> Enum.all?(words, & &1 =~ ~r/^[a-z]+$/)
true

refresh()

@spec refresh() :: :ok

Refreshes the dictionary.

repeated_words()

@spec repeated_words() :: [String.t()]

Returns all the repeated words in the dictionary. Note that repetition counts will be enclosed in parentheses after each word.

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.repeated_words()
["echo (3)", "hello (2)"]

shortest_words(ceil \\ 5)

@spec shortest_words(pos_integer()) :: [word()]

Returns the shortest words in the dictionary (shorter than ceil).

In iex, you may want to run:

IEx.configure(inspect: [limit: :infinity])

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.shortest_words() |> Enum.slice(39, 10)
["act", "add", "ado", "ads", "adz", "aft", "age", "ago", "aid", "ail"]

iex> alias Hangman.Dictionary
iex> Dictionary.shortest_words(2)
["a", "i"]

word_count()

@spec word_count() :: pos_integer()

Returns the number of words in the dictionary.

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.word_count
57713

words_of_length(word_length)

@spec words_of_length(pos_integer()) :: [word()]

Returns all the words in the dictionary of length word_length.

In iex, you may want to run:

IEx.configure(inspect: [limit: :infinity])

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.words_of_length(16)
["characterization", "responsibilities", "sublimedirectory"]

iex> alias Hangman.Dictionary
iex> Dictionary.words_of_length(3) |> Enum.take(10)
["ace", "act", "add", "ado", "ads", "adz", "aft", "age", "ago", "aid"]

words_starting_with(prefix)

@spec words_starting_with(String.t()) :: [word()]

Returns all the words in the dictionary starting with prefix.

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.words_starting_with("monster")
["monster", "monsters"]

iex> alias Hangman.Dictionary
iex> Dictionary.words_starting_with("cock") |> Enum.take(3)
["cock", "cockade", "cockaded"]