By Ben Nitkin on
I recently learned of a travel word game with a few simple rules:
- Start with any word.
- Construct a new word, using all but one of the letters of the original word.
- Repeat until you have a one letter word.
I decided to replicate it using Python and a dictionary file, and here are the results. The program consists of a WordTree class and a small wrapper. Given a word to begin with, the class finds all permutations of the word, less one character. It then spellchecks each one, discarding the gibberish.
Next, it creates a child WordTree class for each of its valid words. Through the magic of recursive processing, it creates a tree of slowly shrinking words.
WordTree has a few features that are just for show. It uses a custom __str__() function that prints a representation of the entire tree, using DOS box characters for prettiness. There are also two levels of notification for progress updates, and the dictionary is customizable.