Note: You can use the app here.
Recently, it feels like everyone I know has been playing a new viral word guessing game, Wordle.
The author made it very easy to show off your score to your friends, which led to a deluge of messages in my group chats: We’re getting a bit competitive.
Now, I’m not normally particular good at word games, so this got me thinking:
How could I give myself an edge at Wordle, without cheating?
I think of myself as a ‘business guy’, not a software engineer, but for a fun-hobby-project I thought I’d see what I could do with the aid of a computer. In the end, this involved making a web-based app, and learning lots of new things. So I thought I’d write about how I made my first ‘useful’ app.
The result is Wordle Companion (Code on Github). It helps you work out which words could be today’s answer based on your previous guesses.
How do you win Wordle?
(If you’ve played Wordle before, you might want to skip this part.)
The aim of Wordle is to guess the five letter word published once a day, in as few guesses as possible, with a maximum of 6 tries. It’s a game of both luck and skill.
Each guess you make gives you progressively more information, as the letters in your guess are colour coded according to three different outcomes:
Green — the letter is in today’s word, specifically, in the position you placed it in your guess
Yellow — the letter is in today’s word, but not in the position you placed it in your guess
Grey — the letter is not in today’s word
You can then use this information to mentally exclude words that don’t fit with the information you have. But what if you didn’t have to do it mentally?
Building Wordle Companion, Step by Step
Permutations, permutations: How many Wordle solutions are there?
Artificial intelligence: Teaching a computer the Wordle rules
It goes both ways: Talking to a computer
Spit and polish: Making a web-app look not terrible on a phone
Publish or perish: Putting a web-app on the internet
1. Permutations, permutations: How many Wordle solutions are there?
We can quickly work out how many possible arrangements there are of 5 English letters. There are 26 possible letters for each of the five positions in the word. This gives:
26⁵ = 11.9m possible combinations
In short, a lot.
But we can obviously be smarter than this, most five letter combinations of letters are not words, like AAAAA or AAAAB.
I was unsure about how the Wordle words were chosen, but assumed the creator must be picking real words he knew. He’d then be more likely to pick more common words, so I went to find a list of common words. Usefully, someone has compiled the 1/3 million most frequent words from the Google Word Trillion Word Corpus. So pretty simple to just find the five letter words from this. This left me with 39,933 words. Seems a much more reasonable starting point.
I looked at these words in a bit more detail. Some of the most frequent ones all looked good: about, other, which, their, there. But when you sort by frequency and go near 25% down the list you get: flore, stant, outil, https and olbia. This Google list of words are actually not exactly words, but rather pulled from a huge set of text typed on the internet. I tried to find out the point in the list where they turn from mainly words to mainly not-words, but it’s a pretty fuzzy boundary.
So I looked for a better set of words.
In my Googling I stumbled across this Tweet:


It turns out all the Wordle solutions are stored in the code loaded on the webpage when you open Wordle. Buried in that, is a list of just 2,314 words which are possible solutions, plus another 8,000 or so you are allowed to guess, but cannot be picked as solutions for a given day.
So, 2,314 words.
2. Artificial intelligence: Teaching a computer the Wordle rules.
(There’s no actual AI, sorry if I mis-sold this)
Armed with my list of words, I needed to create some rules to filter the list after each guess.
For each guess, you get information about 5 different letters. The logic is:
If a letter is green, filter out all the words which don’t have that letter in the position you tried it in
If a letter is yellow, filter out any words that don’t contain the letter and filter out any words that do contain the letter in the position you tried it
If a letter is grey, filter out all the words containing that letter
Clearly searching the list manually is very boring and time-consuming. The type of exercise humans are bad at. So it’s a good idea to teach a computer to do it for you.
I chose to write the code in Python, as it’s the only language I can really do anything in. This isn’t really a post about how to write code, so I won’t bore you with it.
Writing Python, it’s useful to be able to quickly muck around and see the output. I like to use Google Colab - you don’t even have to install Python on your computer.
From this point, it is pretty easy to filter the list down given an input word and which colour each letter is.
3. It goes both ways: Talking to a computer
It’s pretty boring to have to change the code every time you are changing the word you are testing, so I wanted to build a user interface to type in guesses.
User interfaces on websites today (as I understand it) are written in HTML and JavaScript and often use some front end framework tools like React.
However, for novices with these tools, the team that made Plotly (a graph making tool for Python), have made a pretty cool thing called Dash. Dash allows you to build websites using just Python.
A few hours later and I had the below:
This sort-of gets the job done, but it looks terrible, and it isn’t entirely clear what to do.
4. Spit and polish: Making a web-app look not terrible on a phone
Not only did it look bad, the boxes were all in the wrong places, and so it was pretty unintuitive to use. Especially on a phone (which I mainly use for Wordle).
I turned to a helpful front-end library called Bootstrap. Bootstrap was made by some software engineers at Twitter in 2011, when they realised mobile was going to be big. Back then most websites were made for desktop, and were awful when viewed on a phone screen.
Bootstrap allows you to make something that looks good and is easy to use, irrespective of your screen size. I added Bootstrap formatting, expecting a pretty immediate improvement.
It turns out I was pretty naive to think this was going to be a cakewalk as a first timer.
Everything up until this point had probably taken me a day. I spent about 3 days trying to get the user interface to look half reasonable. To be honest, I’m still not totally happy with it, but I couldn’t sink any more time into it without having to admit to myself that the fun-hobby-project had got out of hand.
5. Publish or perish: Putting a web-app on the internet
At this stage, the app was running locally, meaning only on my personal machine. To share it, it needs to be hosted somewhere on the public internet. This is a bit of a daunting task if you’ve never done it before. I have, once or twice.
In principle, you have to get a server (which is basically just a computer), connect it to the internet, give it a unique address, install an operating system, configure it so it has all the stuff it needs to run your website, and then make sure it never turns off ever. And lots of other stuff not mentioned above. This is pretty hard.
This means generally people don’t want to run their own servers (point made in Crypto / Web3 article by Signal’s creator), so there are lots of companies that offer services to help. I chose Heroku, which is pretty amazing for beginners. It abstracts away a lot of the complexity and comes with step by step instructions.
It’s still not totally straightforward. You have to put a few different files together into a folder: your code, instructions on how to run your code, instructions about what 3rd party libraries your code relies on (there are a lot of these), and then any data (say a list of 2,000 words) or images you want to use.
And with that, it was launched.
You can use the app at wordle-companion.herokuapp.com and the code on Github.
If you try it out, do let me know what you think, if anything’s broken, or if anything else would make it better. (I’ll consider feature requests that are both within reason, and within my ability).
What I learned:
Most things written on the internet are not words. Maybe this shouldn’t be a surprise.
Making a website both pretty and functional is hard. I have a newfound respect for front-end developers.
Building a website means bolting a lot of stuff together. Mine is Python + Plotly-Dash + Bootstrap + Heroku.
It’s hard to stop the “fun” getting out of hand. All in, it took me probably a week of work.
But wait!
You might have realised this doesn’t give you the “best way” to beat your friends at Wordle. It filters down the list to see what you can still try. The best thing would be something that could tell you what to guess next!
Well, that definitely gets outside the territory of a fun-hobby-project for me, but there are some much smarter people who have done a better job than this (though you can’t always use their tools yourself).
My favourite is this video by Grant Sanderson, a maths / probability YouTuber. He uses information theory to find the best possible guess, each turn. Worth a watch if you are interested in maths and have 30 minutes.