12 MIN READ TIME

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

Unlock this article and much more with
You can enjoy:
Enjoy this edition in full
Instant access to 600+ titles
Thousands of back issues
No contract or commitment
Try for 99c
SUBSCRIBE NOW
30 day trial, then just $9.99 / month. Cancel anytime. New subscribers only.


Learn more
Pocketmags Plus
Pocketmags Plus

This article is from...


View Issues
Linux Format
May 2024
VIEW IN STORE

Other Articles in this Issue


WELCOME
MEET THE TEAM
Website trackers put Linux usage at over 4% for the first time. Where do you see Linux use increasing and how do you think things will go in the future?
Linux is everywhere
Everyone gets excited when the Linux market share
REGULARS AT A GLANCE
Linux is popular!
Linux has long been a favoured OS for servers and embedded devices but is now increasingly popular for desktop machines, too.
KDE Plasma 6 released
The long anticipated upgrade to the Plasma desktop has been released with huge improvements.
Nvidia moves to block ZLUDA
Ban on using CUDA translation layers in installed files.
VECTOR VEXATIONS
Dave Stokes is a technology evangelist at Percona.
WINE FOR WAYLAND
Alexandros Frantzis is a senior software engineer at
FreeBSD moves to kill 32-bit
FreeBSD is deprecating 32-bit platforms; 32-bit binary support in 64-bit kernels will remain, however.
PostmarketOS moves to Systemd
Phone OS has tentative support for Systemd.
Framework 16 laptop ships
Repairable, upgradable model costs under $500.
Distro watch
What’s behind the free software sofa?
FIXING OFFICE 365
Italo Vignoli is a founder of LibreOffice and
HAPPY BIRTHDAY!
Jon Masters is a kernel hacker who’s been
Kernel Watch
Jon Masters keeps up with all the latest happenings in the Linux kernel, so you don’t have to.
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mailserver
WRITE TO US Do you have a burning
Helpdex
shane_collinge@yahoo.com
BACK ISSUES MISSED ONE?
ISSUE 313 April 2024 Product code: LXFDB0313 In
OBS Studio
Mayank Sharma was bitten by a radioactive download
Moosync
Version: 10.3.2 Web: https://moosync.app Click on the
PhotoCollage
PhotoCollage defaults to a 800x600 canvas, but you
Collector
Version: 1.0.1 Web: https://mijorus.it/projects/collector/ You can open
Patool
Version: 2.2.0 Web: https://wummel . github.io/patool/ You
Warpinator
Version: 1.8.3 Web: https://github . com/linuxmint/ Warpinator lets
Croc
Version: 9.6.12 Web: https://schollz . com/tinker/croc6/ It might
Freedoom
Version: 0.13.0 Web: https://freedoom.github.io You can use
LibreMines
Version: 2.0.0 Web: https://github . com/Bollos00/LibreMines LibreMines has
QOwnNotes
Version: 24.2.5 Web: www.qownnotes.org While QOwnNotes supports
S-tui
Version: 1.1.6 Web: https://amanusk . github.io/s-tui/ Unlike
20 YEARS OF UBUNTU
We dive into the brand-new Ubuntu 24.04 LTS and look back at where it all began and how we got here!
LINUX FORMAT
The #1 open source mag
REVIEWS
AMD Ryzen 5 8600G
The CPU of choice for Chris Szewczyk and his tight budgets.
Deepin 23
Nate Drake is in too deep with Deepin – is this Chinese-made distribution a crouching tiger or a hidden dragon?
KaOS 2024.01
Nate Drake seeks to find some order in KaOS – a distro incorporating the KDE Plasma 6 desktop environment.
Bluestar Linux 6.7.6
Nate Drake finds blue is the colour, after firing up this intuitive and visually stunning Arch-based distro.
Drauger OS 7.6
Nate Drake puts this distribution through its paces – is Drauger a gaming dragon or just a plain drag?
ROUNDUP
Time trackers
This month, Michael Reed is keeping a strict eye on himself and trying to improve his work efficiency by investigating time-tracking applications.
Linux native application
Other options are nice, but we expect a well-integrated Linux app.
Installation complications
The first hurdle is always obtaining and installing the software.
User interface design and use
The ease of daily use. If the application
Extra features
Beyond the basic options, what else can the software do?
Automatic tracking
Insights from hands-free analysis of your activity can often be fascinating.
Cloud options and alternative platforms
Working away from the main computer.
Reports and summaries
For some, this is one of the most important parts of the system.
Time trackers
We’re choosing TimeCamp, a freemium solution that isn’t
LINUX INVADES WINDOWS
Join Nate Drake as he explores Linux’s infiltration of Windows. Have the barriers between operating systems truly been broken?
Learning to love Linux
The early days of Microsoft put it at loggerheads with the growing open source movement, but things are different now.
Linux inside Windows
Run Linux apps on Microsoft’s OS in Windows Subsystem for Linux 2.
VS Studio for Linux
WSL2 integration offers the best of cross-platform development.
Run the Microsoft distro
Rumours are rife but how far will Redmond go to embrace Linux…
Pi USER
Turning the Pi Pico into a custom GPU
Renowned fanatical Pi modder Clem Mayer goes all out and creates a Pi-powered graphics card.
Kaki Pi
From Japan!
Double the fun
NVMe on Pi 5
RASPBERRY Pi TURNS TWELVE!
Les Pounder works with groups such as the
ParrotOS
Les Pounder has watched Hackers at least 12 times and knows what all the books are. Now he just needs a cool haircut and RISC-based laptop.
Bambu Lab X1-Carbon
There’s a reason this Bambu is shooting up all over and Andrew Sink is happy to help it out.
Create notifications from smart sensors
Les Pounder loves building gadgets with the low-cost Raspberry Pi Pico W – and some of them, like this one, even work.
IN DEPTH
The Grapes of Tux
Sommelier Jonni Bidwell shows you how to get your pesky Windows applications running on Linux, as he uncorks the latest Wine release.
TUTORIALS
Audit your system for vulnerabilities
Invulnerable Shashank Sharma has the perfect tool to keep systems safe.
Build a streaming ebook library
Bionic bookworm Nick Peers looks at a free tool that enables you to collate, read and share your digital publications over the internet.
After the kernel, it’s startup time, init!
Mats Tage Axelsson explains how Linux takes you from the kernel to a running system, both today and back in the mists of time.
Ultra-smooth home game streaming
Promising the Sun and the Moon, Michael Reed’s heavenly bodies promise perfect gaming streaming on most PC hardware.
Reviving the MK14 retro home computer
Mike Bedford uses emulation to learn about Sinclair’s first sub-£100 computer, which predated the better known ZX80 by three years.
Clever CAD coding for clients and cigars
Hungarian boy genius Tam Hanna tidies up his underground bunker’s cigar corner with a bit of creative 3D printing.
How to fix glitching Steam Deck games
Despite amazing work, there’s plenty of incompatible Steam Deck games, thankfully fixes are at hand, but nothing so far for Neil Mohr.
ADMINISTERIA
Tips for managing Docker containers
Generous-minded Stuart Burns has years of Docker experience under his belt and is keen to share his knowledge with other sysadmins.
Collaborate with OnlyOffice DocSpace
Nowadays, online document collaboration is a must. OnlyOffice DocSpace allows organising this effectively. Kseniya Fedoruk shows how to set it up.
Make AI work for you
Want to get more from the best-known AI service on the planet? Barry Collins and Neil Mohr explain how to make AI work for you.
CODING ACADEMY
Pixel-perfect Asteroid collision detection in C
Did those pixels touch or just pass by? David Bolton demonstrates a method of checking collisions with lots of objects on screen.
Chat
X
Pocketmags Support