Finding anagrams by hand is fun, and not that hard, but I thought it’d be an interesting challenge to come up with an algorithm that filters a dictionary of tens of thousands of words down to a list of words that are spellable using some arbitrary set of available letters.
The algorithm I came up with converts each word into a 26-index array of integers, representing the quantity of each letter (A-Z) required to spell the word. This can be done quickly for every word in a dictionary, and stored efficiently in memory.
More importantly, though, finding out which words in the dictionary can be spelled with some arbitrary set of letters is as simple as subtracting each word from the available letters. If the result contains any negative numbers we can’t spell that word. All spellable words are put in a text box, and updated automatically when the user enters a new letter in either the
anagram box. The resulting program is pretty fun to use!
The code is on github. You can run the Python version locally by following the Readme.md file instructions.
Written on August 6th, 2018 by JPH