Werds (werds v1.0.6)

A module to generate valid word variants from a base word. Will also find anagrams of a word.

Summary

Functions

Get anagrams

Check that the number of letters in the candidate word are less than or equal to the number of letters in the word we used as a source

This takes a string mask like "...x.." and creates a string that can be turned into a regex for searching

Generate wordle suggestions

Give us a list of words from the dictionary, using the letters from source, that conform to the match pattern. The match looks like a "normal" regex, but when we have a . it matches the unused letters from the source word

Functions

anagrams(word)

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

Get anagrams

check_word(word_char_counts, source_char_counts)

@spec check_word(map(), map()) :: boolean()

Check that the number of letters in the candidate word are less than or equal to the number of letters in the word we used as a source

make_mask(source_word, match_string)

@spec make_mask(String.t(), String.t()) :: String.t()

This takes a string mask like "...x.." and creates a string that can be turned into a regex for searching:

Say the word is "banana" and we want to see words that will match a pattern like "..ana", as in each . would match the unused characters from our source word. You would need /[ban][ban]ana/ - this method generates it.

wordle_suggestions(letters, keys)

@spec wordle_suggestions(%{required(integer()) => String.t()}, %{
  required(String.t()) => :default | :correct | :misplaced | :incorrect
}) :: [String.t()]

Generate wordle suggestions

letters: a map of letter positions and their values keys: a map of letters and their status :default - letter is not used :correct - letter is in the correct position :misplaced - letter is in the word but not in the correct position :incorrect - letter is not in the word

The function will return a list of words that match the criteria

In practice we only use incorrect and the map of letters because any letter we haven't yet checked, inluding the ones we know the position of, could be in the word. So we only need to check the letters that are not in the word.

words(source_word, match_pattern)

Give us a list of words from the dictionary, using the letters from source, that conform to the match pattern. The match looks like a "normal" regex, but when we have a . it matches the unused letters from the source word

The default search is caseless and will find acronyms and proper names, pass an empty options list to turn this behaviour off

Options [:proper_names] and [:acronyms] will do the obvious thing

The option [:standard] turns off caseless and will only find "proper" words

words(source_word, match_pattern, options)

@spec words(String.t(), String.t(), [term()]) :: [String.t()] | {:error, String.t()}