## Motivation
Wordle is a puzzle intended to exercise your vocabulary and logical reasoning skills. But what if you just want to procrastinate by writing some simple regular expressions? Read on to find out how!
## Prerequisites
- A word list matching the language of the puzzle is required.
On Debian you will probably have a symlink at
/etc/dictionaries-common/words
pointing to a suitable list. If not,apt install wamerican
or similar. grep
## Encoding the puzzle
Every time you guess a word, the letters are colour-coded by the puzzle to provide information about the solution. This information can be encoded as regular expressions to find the solution - often within two or three guesses, and almost always within four.
Here’s a walkthrough of 2022-10-22’s puzzle.
First I guess STEIN.
If the letter is green, it is in the correct location, which is encoded directly by placing the letter in the regex.
$ grep -Ei '^s....$' /etc/dictionaries-common/words
If the letter is grey, it is not in the solution. This is encoded by invert-matching the grey letters.
$ grep -Ei '^s....$' /etc/dictionaries-common/words | grep -vEi '[tn]'
If the letter is yellow, it is in the solution, but not in that location. This is encoded by inverse matching the letter at that location, and then matching those letters anywhere in the word.
$ grep -Ei '^s.[^e][^i].$' /etc/dictionaries-common/words | grep -vEi '[tn]' | grep -i e | grep -i i
Seiko
seize
shied
shies
shire
sided
sides
sidle
sired
sires
sises
sixes
sized
sizer
sizes
skied
skier
skies
slice
slide
slier
slime
smile
spice
spied
spiel
spies
spike
spire
swipe
The information provided by the puzzle after just one guess has already narrowed the possible solutions down to 30 words.
My next guess is SLIDE.
Encoding this additional information the same way gives just a single possible answer.
$ grep -Ei '^s[^l]i[^i][^e]$' /etc/dictionaries-common/words | grep -vEi '[tnd]' | grep -i e | grep -i l
spiel
Hooray, two minutes successfully wasted!