Wordle is a simple word game where you try to guess a 5-letter word each day. This gist contains a small Fish function to help you narrow down the list of possible answers based on the scores from each guess.
Guess the Wordle in 6 tries.
- Each guess must be a valid 5-letter word.
- The color of the tiles will change to show how close your guess was to the word.
Examples
W is in the word and in the correct spot.
I is in the word but in the wrong spot.
U is not in the word in any spot.
To play with this function, install fish. Then add the code in this gist to a new function file: ~/.config/fish/functions/fish_helper.fish
.
$ wordle_helper -h
wordle_helper - Fish function to help with Wordle puzzles
Usage:
wordle_helper [--green <exact_positions>] [--yellow <not_exact_positions>] <guess>
Options:
-h, --help Print help
-g, --green Position of letters that matched exactly (format: 12345)
-y, --yellow Position of letters that are not exact (format: 12345)
Example:
$ wordle_helper -y 3 SLATE | wordle_helper -g 14 -y 2 CAROM
COCOA
Make a guess on today's Wordle.
Let's say you start by guessing SLATE
. You get a score of:
We got yellow in position 3, and no green. That means there's an A
, but no S
, L
, T
, or E
.
Let's run wordle_helper -y 3 SLATE
. You should get 800+ possible words that match that score.
We didn't do very well on our first guess. Let's take another.
From that list, let's guess CAROM
.
This time we did a lot better. We got green in positions 1 and 4, and got yellow in position 2 this time. That means
C
and O
are right, but we still haven't found where A
goes. Let's run wordle_helper
again, but this
time let's pipe the words from the first result into the second. That way, the all our guesses filter the word list.
Pressing the up arrow on a Fish prompt gets your last command.
$ wordle_helper -y 3 SLATE | wordle_helper -g 14 -y 2 CAROM
COCOA
...
Whoa! For our 3rd guess, there's only one choice left that fits! Thanks Wordle Helper!
The Fish function is pretty well commented, but there are a few regex tricks we use.
First, we need to get all the possible 5-letter words. We get that either from the system dictionary file (on macOS, that is /usr/share/dict/words
), or we pipe the filtered word list in from the results of a prior guess.
Next, if our guess gets scored with green
letters, we can narrow the word list down really fast. For example, our CAROM
guess where the C
and O
in positions 1 and 4 were correct, the string match
regex is simply ^C..O.$
.
Similarly, if our guess gets scored with yellow
letters, we know that the letter is in the wrong place, but also exists in
the word. Filtering words on a single letter match is simple, and then similar to the green
regex, we filter words with A
in the wrong place with ^.[^A]...$
.
Instead of just showing the possible answers alphabetically, the helper could simulate the best next guesses based on the remaining possible answers and sort by which guesses would be better than the others. It wouldn't be that hard to turn this into a complete Wordle solver, but the goal isn't to take all the fun out of playing.
Depending on your system's dictionary file, you may run across a word that isn't in your dictionary, in which case this
function won't work and will lead you astray. For example, the word SANER
is not in my macOS dictionary file, but is a valid
5-letter Wordle answer:
$ cat /usr/share/dict/words | string match -re '^sane'
sane
sanely
saneness