Code to generate close-to-optimal guesses for the Wordle puzzle game. The game asks the player to guess a hidden word by making repeated, one-word guesses. For each guess, the game returns a "coloring" that indicates, for each letter, whether the letter is in the hidden word and also whether the letter (if in the hidden word) is in the correct position. There are possible colorings, where n is the word-length.
The algorithm uses a greedy approach to find the hidden word. At each step, the algorithm finds the guess that maximizes the entropy of the distribution of remaining possible hidden words over the possible colorings. Based on the coloring generated by the guess, the algorithm is able to iteratively restrict the set of possible hidden words until only the correct hidden word remains.
Pursuing a maximum-entropy strategy is boring, but reliable! The app is always able to find the Wordle in at least 6 guesses. In a rare few cases it gets it in 2 tries. But, sadly, it will never achieve the dream of the Wordle hole-in-one, as it chooses "SOARE" as maximum-entropy starting guess.
Also by virtue of this approach we do quite well even against an adversarial opponent like Absurdle!
Because of the dynamic approach used there, to get interesting results please try the --custom-start
option.
Finding the hidden word in 5 or 6 tries was typical of my Absurdle experience.
This algorithm is not truly optimal (See Cyrus Freshman's leaderboard), but performs almost as well as exhaustive methods, with an average guesses-per-word of 3.53.
Precomputing the colorings for the Wordle wordlists takes about a minute (73 seconds) but only needs to be completed the first run of the application. Finding maximum-entropy guesses takes less than a second for these small word-lengths.
Install using pip:
python -m pip install git+https://github.com/grahamtholt/wordle_solver.git
To use the simple commandline app:
$ python -m wordler
Reading precomputed data...
Guess SOARE (entropy 5.89)
Enter Wordle response for "SOARE" (0=gray, 1=yellow, 2=green): 00000
Guess CLINT (entropy 5.51)
Enter Wordle response for "CLINT" (0=gray, 1=yellow, 2=green): 01102
Choose randomly from "LIMIT" or "LIGHT"
Here's an example with Absurdle:
$ python -m wordler --custom-start arise
Reading precomputed data...
Guess ARISE (entropy 5.82)
Enter Wordle response for "ARISE" (0=gray, 1=yellow, 2=green): 00000
Guess MULCH (entropy 5.21)
Enter Wordle response for "MULCH" (0=gray, 1=yellow, 2=green): 00000
Guess GOODY (entropy 3.25)
Enter Wordle response for "GOODY" (0=gray, 1=yellow, 2=green): 02202
Guess BLITZ (entropy 2.00)
Enter Wordle response for "BLITZ" (0=gray, 1=yellow, 2=green): 00001
Choose "WOOZY"
See the included example.py
for an example of guessing the hidden word "crimp" for Wordle using the backend.
Many thanks to Josh Wardle, creator of Wordle, qntm, creator of Absurdle, and Cyrus Freshman, who hosts the Wordle bot leaderboard.