If you’ve been on the Internet in the last few weeks, you’ve probably heard about a wonderful new word game called Wordle. Just in case you haven’t heard of it, or if you’re confused at all about it, let me give you a quick intro before I give you a way to help you play the game.
Where to Find Wordle
Wordle is a web-app at powerlanguage.co.uk/wordle Don’t be confused by the imposters in the various app stores; they are not the real deal. Apple is trying to squash them as quickly as they’re spawning, and I presume Google is doing the same thing. The problem is that the developer of Wordle, a gentleman named Wardle, refuses to monetize his game. He made it for his wife and he gave it to the world, and everyone is trying to make money off of his generosity.
An important part of the success of the game is that you can only play it once per day, and everyone who plays it on a given day is trying to guess the same word. If you do succeed, he built into the game a way to share your success and even show how many guesses you took to win, and yet in a way that does not spoil it for everyone else playing on that day.
Now that you know where to find it, let’s give a tiny bit of information on how to play. You can find full guides on it everywhere but I have to lay out the basics in order to talk about a way to help you play the game.
The goal of the game is to guess a five-letter word. You get exactly 6 chances to guess the word. The game board is 5 letters across and 6 high. Each word you guess gives you clues to the final answer. As you make each guess, the letters are color-coded. If a letter in a word you typed is not in the answer, the letter will turn grey when you hit enter. If it’s in the word but in the wrong place, it turns a dark mustard color. If it’s in the word and in the right place, it turns green.
With these clues, you can make a more educated second guess. Your first guess might show the letter L green in position 5, but A is mustard in position 1. You now know the word has the letter A but not as the first letter, and it has an L as the 5th letter, and you also know that the other 3 letters in your original word will not be in the final answer.
As you guess new words, with each guess you’ll get more information about what letters are in and not in the word, and the positions of those letters. One trick of the game is that there may be two of a letter and it doesn’t tell you that. In our example, we learned that there was an A in a position other than the first character, but that doesn’t mean there aren’t two As in the word.
Playing Fair, Getting Help, or Cheating
If you really enjoy stretching your brain and working hard on a puzzle like this, you’ll work on this on your own and not try to find any assistance. But if you get bored quickly with games and puzzles like I do, maybe you want a way to get some extra help. Yes, it’s missing the point of playing the game in the first place, and yes by most measures getting help is probably cheating. But as long as I don’t pretend I’m doing it by myself, it makes me enjoy it more.
The first time I played Wordle was on game 208. I was paralyzed looking at this blank slate. How many 5-letter words ARE there anyway? Where would one start? I thought of the word SLACK, but that was wrong. The A was indicated as being in the answer, but not in position 3. As soon as slack was in my head, I could not think of any other words but black, snack, flack … you see my problem, right? I resorted to Googling “five-letter words” for inspiration to make a guess that didn’t rhyme with slack.
Once I got rolling with a new word, I figured out how the game was played and got to the answer in 5 of the 6 tries. The answer to puzzle 208 was ABBEY. Since that was days ago, I’m not spoiling the game for anyone but those who might choose to roll their system clocks back!
Taming the Terminal Chapter 17
I tell you all this because I realized that Bart Busschots has given us another way to “enhance” our skills, otherwise known as cheating. But it’s really cool, I promise.
I remembered that in our Taming the Terminal series chapter 17, Bart started teaching us about regular expressions. Regular Expressions are a way to search for text strings where you know something about what you’re looking for but not enough information to find it without assistance.
Bart chose as an example the idea that you’re working on a thorny crossword puzzle, and you need a word that fits into the pattern “something, e, something, something, f, something. This is exactly the kind of problem we have to solve with Wordle.
Even the simplest of regular expressions looks like a cat walked on your keyboard. I’ve successfully done a few regular expressions, but nothing too advanced. Luckily, for our needs, we don’t need to get too crazy with our regular expressions. We’ll only use a few characters to do it.
Where Do We Find the Words?
But before we actually create a regular expression, you’re probably wondering where you’re going to do the search. On every Mac, in Applications/Utilities there’s an application called Terminal. This is a command-line tool that lets you do all kinds of swell things. If you run Linux, you have a command-line tool there as well.
Bart explained in TTT17 that inside the operating system is a built-in dictionary of English words. (I confirmed with @sir_brich on Twitter that even if your system language is non-English (theirs is Italian), the dictionary is still in English) The dictionary is in the location
/usr/share/dict/words on both Mac and Linux. You won’t need to remember that because you can just copy and paste it from these instructions.
To start a regular expression matching exercise, you’re going to use the command
egrep. If you care, it is a variant of
grep stands for Globally search for a Regular Expression and Print matching lines. Aren’t you glad you asked?
Ok, so we know where the dictionary is on our system, and we know that egrep is the command to start the search, all we need to do is write a regular expression.
With regular expressions, you can bookend them with characters that mean “starts with” and “ends with”. The caret symbol
^ (the little hat above the 6 on a US keyboard) means ‘starts with’ and the
$ symbol means the end.
If we put 5 characters between the
^ and the
$, in the regular expression, then egrep knows to search for five-letter words. Throw that regular expression inbetween quotes because sometimes things get weird if you don’t. If you don’t know any of the letters in the search, you would type a
. for every character. For example, if you wanted to see every 5-letter word in the English language, then you’d write:
egrep '^.....$' /usr/share/dict/words
That’s fun, and better than googling to see 5-letter words, but it’s a very long list. Let’s make a search where we know a little more about the word. If we know where a specific letter is in the word, we can use the letter instead of
. to narrow our search. When I was playing Wordle 208, I had figured out that the 2nd letter was a “b” and the 4th letter was an “e”. We can update our
egrep search to:
egrep '^.b.e.$' /usr/share/dict/words
It turns out there are only 7 words in English that match this pattern.
When you look at that list of words, there’s really only one common word that would likely be in the puzzle, and that’s “abbey”, which turned out to be the answer to Wordle 208. It did make me wonder whether I could download a common English dictionary, but that seemed a bit over the top. Plus, I couldn’t easily find one.
This won’t always give you the answer to the puzzle. When Steve was playing Wordle 210, he knew that the 2nd letter was “a” and the 5th letter was “c”. I ran the same regular expression pattern:
egrep '^.a..c$' /usr/share/dict/words
There were a lot of words in the result of that search, but only four of them were common: basic, havoc, magic, and panic. You wouldn’t get the final answer with four to choose from, but if you used this trick early in the game it would be a great basis to narrowing things down for your next guess.
All this is well and good when you know exactly where the characters are. But what if you know a character is in a word but you don’t know if it’s in the 4th or 5th position. Regular Expressions allow you to use a symbol to mean “or” so you can search for the 4th or 5th position. To designate “or” we use the “|” (pipe). It looks like a vertical line and is above the forward slash on an English keyboard. With the “|” doing the job of “or” for us, we can string two of these regular expressions together to ask for 5-letter words with an “a” in the second position, and a “c” in the 4th or 5th position.
egrep '^.a.c.$|^.a..c$' /usr/share/dict/words
This returns about 40-50 results, but only 12 of them are what I would consider common English words. 12 to choose from again won’t solve the puzzle on the last round, but it could help stimulate your brain when making a mid-game guess.
Claus and His Python Script
Noted NosillaCastaway Claus Wolf, aka @mactopics on Twitter got inspired by a tweet I posted about using regular expressions to help with Wordle. He tagged me and Bart with a link to a video he made of an even more advanced way to assist Wordle gameplay. He actually wrote a Python script to help search the built-in dictionary! He gave me permission to post the video here, after rolling back his system clock to make sure he didn’t post today’s answer!
Also, remember I said I didn’t download a common word list because I didn’t know where to find it? Well, Claus found Wardle’s GitHub repository and he’s got the word list posted there. If you want to download it yourself, you can find it at github.com/powerlanguage/word-lists.
I know I’m still going to get hater comments that this is cheating. But maybe for some of us, it makes the game fun where we’d never play again if we didn’t have some help. So if you’re a purist, I hope you learned something here that might be useful for other applications and that you don’t judge the rest of us for having some nerd help with our gameplay.
If you liked this, and want to learn more about the Terminal, I can highly recommend the Taming the Terminal podcast in your podcatcher of choice, and you can download the free eBook in the format of your choice at podfeet.com/tttbook or view it online and listen along to the podcast at ttt.bartificer.net.