For those who are unfamiliar with Spelling Bee, you are given seven letters to make words with. In the center of the list, you have one character that must be used in every word. Each word needs to be a minimum of four characters long.

It is a simple concept, but I thought I could speed up the process. I figured I could get every iteration of the characters and then compare them to some kind of spellchecker to verify they are actually words. From there I would be able to quickly input the words and call it a day.

Creating the iteration portion wasn’t very difficult. I did it in an admittedly inefficient way for my mental exercise and just did nested loops for the words.

Image for post

Now, like I said, this is a pretty over-coded way to do this, but I tried using a couple iteration tools like using the Iteration library and importing the Combinations function. This however would only give me a minimal number of iterations and wouldn’t function to the level I needed it to get to. For example, I was only getting around 300 combination with the Combinations function. However, when I used the loop for the four character combinations, I found 2401 combinations. The five word combination found 16807.

Now, once I had my lists of combinations as a part of my test, I need to find which combinations are actually words. Though for computational efficiency, I first removed all combinations of without the necessary letter. In my test case the letter ‘T’. This cleans our list down from roughly 19,000 to around 14,000.

#python #spelling #spelling-bee #python-libraries #new-york-times

Spellcheck in Python
1.50 GEEK