anagram v1.0.0 Anagram.Finder
Summary
Functions
Add a word to our anagrams dictionary
Find all anagrams of the given word (from our dictionary). Returns a list
Canonicalise the word by sorting it’s characters
Test if our candidate word can be made using only the given letters (case insensitive)
Load the given dictionary for later use by our anagram finder
Find all words in our given dictionary, which can be made from a subset of the given letters (case insensitive)
Functions
Add a word to our anagrams dictionary
iex> Anagram.Finder.add_word("sober", Map.new)
%{"beors" => ["sober"]}
iex> ["sober", "robes"] |> Enum.reduce(Map.new, &Anagram.Finder.add_word/2)
%{"beors" => ["robes", "sober"]}
Find all anagrams of the given word (from our dictionary). Returns a list
For repeated searches its highly recommended to preload the dictionary using load_dictionary/1 and pass it to this function
The default dictionary will be web2, ie assumes a unixy OS. Load your own dictionary if this isn’t present/wanted
Canonicalise the word by sorting it’s characters
iex> Anagram.Finder.canonicalise("hello\r\n")
"ehllo"
Test if our candidate word can be made using only the given letters (case insensitive)
Load the given dictionary for later use by our anagram finder
Format is a map, where
- the keys are a normalised form of the word (lower case + sorted)
- the values are a list of anagrams of these letters
Finding anagrams is simply a case of normalising a candidate word and then looking up all the anagrams from our dictionary