4 Pics 1 Word Solver with Python and Google App Engine
TL;DR: http://four-pics-one-word-solver.appspot.com/
One of the word puzzle game that I’ve been playing this past month is the popular 4 Pics 1 Word Game, from the Google Play Store page it says: 4 pictures that have 1 word in common.
For a non-native English speaker like me, with just pictures and random letters, some words are hard to find so I thought of a way to find the correct words. Looking at the game it provides the exact number of letters of the correct answer and the most important of all the letter choices. So armed with these facts we can easily tell if a candidate word is a subset of the letter choices.
But you may ask where to get those candidate words to compare with the letter choices? Luckily, someone on the internet has compiled a dataset - a list of unique common words that he extracted from Google Books. Click here to learn more.
Now that we have our dataset - a corpus of 97,566 unique common words that can be found on Google Books, we can then proceed to write a python script to test if our solution is correct.
Example Question:
- Word length: 5
- Letter Choices: WATEJRNLVRLN
- Answer: WATER
The script got 53 word candidates. Cool! And by the way the dataset also provide a frequency count of the word occurence in Google Books data. That can be useful to sort our list of candidate word relevance. Perfect!
Since our script works, our solution is correct. I have implemented a web service for this http://four-pics-one-word-solver.appspot.com/ try it!
Loading Data on App Engine
When I implemented the web service in Google App Engine, I tried to save the dataset all the 97,566 in the datastore which turned out wrong! I hit the datastore free quota. And later found out that it is much better to store it in memory and it will not accrue an API cost. The way to do this is to store the list of words in the dataset into a data structure and searialize it (pickle). Then later you can access the data at runtime by de-searializing it (unpickle). See below.
Now go play 4 Pics 1 Word, and if your stuck you know where to go! :-)