PYTHON
Solve word puzzles with clever code
Living conundrum Matt Holder discovers how to use Python to improve his puzzle-solving skills when watching Countdown.
OUR EXPERT
Matt Holder is an IT professional of 15 years, Linux user for over 20 years, homeautomation fan and selfprofessed geek.
QUICK TIP
The full source code can be downloaded from https://github.com/mattmole/LXF-Countdown-Word-Solver
We are going to create a program in Python that W can solve word puzzles. In the UK, we have a long-running game show called Countdown, which has three types of round:
• Numbers: One contestant picks six unseen cards, each containing a
number. A random number is then generated by one of the hosts and the two contestants have 30 seconds to use the numbers to calculate the generated total. It is not always possible to reach the generated value, so the nearest gets the most points.
• Words: One contestant picks nine unseen cards from two piles –
vowels and consonants. The contestants then use the 30-second countdown period to find the longest word possible from those letters. If both contestants find the same length word, they both get points equal to the length of the word, but if one gets a longer word, only that contestant gets the points.
• Conundrum: The final round of the quiz is called the conundrum. The contestants see a nine-letter word with its letters jumbled up, and they use the countdown period to work out the mystery word. The winner of this round is awarded 10 points.
With that introduction done, let’s look at what we are doing in this article. We are taking Countdown’s words round and generating a piece of Python code to find words from a series of letters. The program will be capable of using letters you enter (should you wish to play along while watching the TV show) as well as generating a random set of letters. Once words have been discovered, we will be able to display them to screen and write them to a file as well.
The Countdown show’s set looks very similar to the one shown in the official game.
CREDIT: Barnstorm Games, Countdown The Official App
So, let’s begin. The first thing to do is create a new directory to start the project. Open your favourite IDE and create a file called countdown.py. If needed, install any Python add-ons for the IDE and set the language of the program you are writing to Python. When running the program, if any libraries are missing, they can be installed using the command structure below. The rich library is the most likely one to be missing and it allows the colouring of text in the console. $ pip install rich