Play, Solve, and Analyze Wordle
Near the end of an introductory Python course that I teach at BYU-Idaho, students must write a program about a topic that they choose. In 2022, I decided that I should also choose and write a program so that I demonstrated what the students are required to do. I enjoy playing the word game called Wordle® and chose to write one or more programs related to it.
* Wordle is a registered trademark of the New York Times Company.
Wordle is a game in which a player has six chances to guess a five-letter word. After each guess, the game responds with a clue that tells the player which letters are in the secret word and which are not and which letters are in the correct position and which are not.
Four Programs
I enjoyed writing the Python code so much that instead of writing one
program and a test file as my students are required to do, I wrote four
programs and a test file. You can download all of the code in this
word_game.zip
file or
you can download the individual programs from the following list.
play.py
- A clone of Wordle implemented in Python that allows a user to play in a terminal or console window.
solve.py
- Accepts the clues from a game of Wordle and prints a list of words that match the clues.
analyze.py
- Analyzes all the words in a list of five-letter words and produces groups of four words that have no letters in common. These groups of words are useful for playing Wordle because each group tests 20 letters in a Wordle game.
extract.py
- Builds a list of five-letter words by extracting them from a text file.
test.py
- A Pytest file that verifies the correctness of the other programs.
Best Words
According to analyze.py
, the best group of four words to
begin a Wordle game with are "snare", "block", "fight", and "dumpy".
Notice that none of the words have letters in common with the other
words. By beginning a Wordle game with these four words, you will have
tested 20 letters in four guesses. This will make it easy to guess the
word in your remaining two guesses.
Here are two example games of Wordle using the four words: snare, block, fight, and dumpy. Notice how each of the four words finds or eliminates five letters.
Remaining Letters | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
S | N | A | R | E | B | C | D | E | F | G | H | I | J | K | L | M | O | P | Q | T | U | … | |
B | L | O | C | K | C | D | E | F | G | H | I | J | M | P | Q | T | U | V | W | X | Y | Z | |
F | I | G | H | T | C | D | E | I | J | M | P | Q | T | U | V | W | X | Y | Z | ||||
D | U | M | P | Y | C | E | I | J | Q | T | V | W | X | Z | |||||||||
T | W | I | C | E | Congratulations! | ||||||||||||||||||
Remaining Letters | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
S | N | A | R | E | B | C | D | E | F | G | H | I | J | K | L | M | O | P | Q | R | S | … | |
B | L | O | C | K | D | E | F | G | H | I | J | M | P | Q | R | S | T | U | V | W | X | … | |
F | I | G | H | T | D | E | J | M | P | Q | R | S | T | U | V | W | X | Y | Z | ||||
D | U | M | P | Y | E | J | Q | R | S | T | V | W | X | Z | |||||||||
W | R | E | S | T | E | J | Q | R | S | T | V | X | Z | ||||||||||
R | E | S | E | T | Congratulations! |