Introducing Word Wizard
Put some letters into the search box. It doesn't even have to be a word. Once you click search, it will search the dictionary for any words that can be made with the letters you entered.
How it works
Step 1. Eliminate Words
When you click search, the letters are quickly compared against all the words in the Hunspell Dictionary, removing any words that don't have your letters. So if you type "cat", "dog" will be eliminated from the dictionary because it doesn't share any letters. This is just to make the dictionary smaller and easier to search in the next steps.
Step 2. Create a fancy "Word" object
Now that our dictionary is a little smaller, we create a "fancy word object" that consists of: The Original Word: "Cat" -and- Letters Left: "Cat"
We make a fancy word object for each word left in the dictionary
Step 3. Find Matches
This is the hard part. The program is only supposed to find exact matches, or words made from part of the original letters. So with the letters "cat", the words "act" and "at" would be good matches. But "Attack" wouldn't, even though it is close. The way this works, is every single letter is compared against the dictionary of "Fancy Word Objects". If a letter is found, it is removed from "Letters Left".
So, for example if our letters are "TCA", we'll start with "T". Here is our dictionary: Original Word: cat Letters: cat Original Word: act Letters: act Original Word: at Letters: at Original Word: attack Letters: attack We look at every word in the dictionary, removing the letters. If any of the words has no letters left, we add that original word to the list of matches!
After going through letter "T", the dictionary looks like this: Original Word: cat Letters: ca Original Word: act Letters: ac Original Word: at Letters: a Original Word: attack Letters: atack
After going through letter "C", the dictionary looks like this: Original Word: cat Letters: a Original Word: act Letters: a Original Word: at Letters: a Original Word: attack Letters: atak
After letter "A", the dictionary looks like this: Original Word: cat Letters: --> No letters left! It is a match Original Word: act Letters: --> No letters left! It is a match Original Word: at Letters: --> No letters left! It is a match Original Word: attack Letters: atak
The hardest part was finding a good dictionary of words. My first attempt used the standard Unix word list:
/usr/share/dict/words. This list was nice, and huge, though it contains a bunch of crazy words (that I've never heard of) so it actually wasn't that helpful, as these games seem to use normal-ish words. My second attempt at a dictionary was to use the English Hunspell dictionary. That dictionary is much more useful, but the version I downloaded was full of proper nouns and letters-not what I wanted. The words there were also marked up with some extra stuff, describing the words. I wrote a small python program to strip all the unwanted stuff out.
import re with open('words2.txt', 'r') as infile, open('words3.txt', 'w') as outfile: for line in infile: if re.match('^[A-Z]+', line) is not None: print line elif re.match('^[0-9]+', line) is not None: print line else: # It is a normal word # Get any extras off newWord = line.split("/").strip("\n") outfile.write(newWord + "\n")
I was left with a handy tool for impossible Word Crossy games!