Wordhelper takes a list of letters on the command line and generates a list of words you can spell. I built it to help me cheat at board games.
I was intensely dissatisfied with how slow my original wordhelper was, so I decided to make a new version using a somewhat faster and prettier approach. What I did was to use a data structure called a trie. It's pretty neat.
This is implemented in wordhelper_trie.cpp
How it works is as follows:
- I insert all of the words found in 'words.txt' into the trie
- Put the set of letters into a multiset
- Do a depth first search of the tree, noting when a node that is the end of the word is found. -At each recursive DFS call, remove the letter of the current node from the set, and call DFS on the set without the letter.
This is implemented in wordhelper.cpp
Disclaimer: This is terrible. It basically worked by:
- inserting all of the letters into a vector of chars
- generating a power set enumeration of that vector
- generating all of the combinations of all the power sets, and then putting all of those combinations into a new vector of strings
- check all of the strings that were permuted against the dictionary
As usual, please roast my code! I love feedback, and I don't care if you're nice about it or not.