Our June 2021 cohorts are filling up quickly. Join our free webinar to Uplevel your career
0%
100%

What Is Wordle and How to Create a Wordle Solver

Posted on 
February 8, 2022
|
by 
Team Interview Kickstart

Attend our Free Webinar on How to Nail Your Next Technical Interview

WEBINAR +LIVE Q&A

How To Nail Your Next Tech Interview

Hosted By
Ryan Valles
Founder, Interview Kickstart
Our tried & tested strategy for cracking interviews
How FAANG hiring process works
The 4 areas you must prepare for
How you can accelerate your learnings

Wordle, a simple word game created by Brooklyn-based software engineer, Josh Wardle, has gone viral! What started as a fun game for Josh and his wife and family has over 3 million players today (The Conversion). In fact, Wordle was recently bought by The New York Times (for an undisclosed low-seven-figure price) and will soon be moved to their website.

In this article, we’re going to look at Wordle from a software engineer’s lens and discuss different algortihms that can be used to solve Wordle. The intention is not to “hack” the game (because that’s no fun!) but to understand what Wordle is and the logic behind solving the most popular game on the internet today.

Here’s what we’ll cover:

  • What Is Wordle and How Does It Work?
  • Tyler Glaiel Algorithm to Create a Wordle Solver
  • Mahmood Hikmet Algorithm to Create a Wordle Solver
  • Andrew Taylor Algorithm to Create a Wordle Solver
  • How to Design Your Own Wordle Solver AI Bot

What Is Wordle and How Does It Work?

So, what is wordle? If you’re here, you’ve probably played the game and know how it works. But let’s quickly go over it, just to be sure.

Wordle (not to be confused with a word cloud) is a word game where you are given six chances to guess a randomly selected 5-letter word. While making each guess, you have to input a valid 5-letter word. 

After each guess, the colors of the tiles change to show you how close your guess is to the final word. Here’a an example of a guess in Wordle; let's say you guess the word "THOSE":

In this Wordle guess example:

  • Green means that the final word contains the letter in the same position.
  • Yellow means that the final word contains these letters but their positions differ from the position of these characters in the guessed word.
  • Grey means that the final word does not contain these letters.

The player keeps getting such hints with each guess and gets 6 guesses to find the right word.

You can use this information to make your next guess, moving closer to the right answer with each guess. But, remember, you only get 6 guesses.

There have been several attempts to create algorithms that could solve the game with more and more accuracy. We’ll look at some of these algorithms to improve guessing accuracy (without resorting to Googling the answers!)

Before we get to the algorithms, let us look at a couple of interesting insights from the source code of Wordle:

  • There are a total of 2,315 possible solutions to the game.
  • There are 12,972 different words that it accepts as guesses. There's a separate set for the guesses so that the player cannot try weird scrabble words like "ABDEE."  

Tyler Glaiel Algorithm to Create a Wordle Solver

In order to find the best starter words for solving the game, Glaiel, in his Medium article, came up with an algorithm that gives a hypothetical score to each word in the list of possible guesses. The algorithm behind giving that hypothetical score is:

Every possible guess is checked against every possible solution. Desirable green letters are worth two points, less certain yellow ones are worth one point, and the useless grey ones are worth zero points. At each step, the guess with the highest average score is returned as the guess to be made. In his study, he found that:

  • SOARE: This word had the highest score among all the potential guesses in Wordle. On average, it finds the solution with 3.69017 guesses. However, this was often not fast enough to help players get to the solution; it takes 8 guesses to find the solution in the worst-case scenario.
  • ROATE: This is the word that was able to get to solutions the fastest. On average, it takes 3.49417 guesses to find the solution. Also, it has a worst-case of 5 guesses.

Mahmood Hikmet Algorithm to Create a Wordle Solver

Hikmet designed a Wordle solver tool called Unwordle to help you solve the puzzle with a 99.3% success rate. He came up with an algorithm that works by deducing the frequency at which certain letters appear in the list of possible solutions and ignoring other guesses. That is, the words that use the most popular letters in the list of solutions are considered the best starting words to guess.

After each guess, certain words are eliminated from the list of possible solutions; therefore, the list keeps converging with each guess. It basically examines the list of possible answers in Wordle to figure out the best possible starting guesses. These starting words are listed in order of their effectiveness:

  • SLATE
  • SAUCE
  • SLICE
  • SHALE
  • SAUTE
  • SHARE
  • SOOTY
  • SHINE
  • SUITE
  • CRANE

Andrew Taylor Algorithm to Create a Wordle Solver

Andrew Taylor came up with a combination of the above two strategies. It assigns a numerical score to each potential Wordle solution, with the lowest score signifying the best solutions worth guessing. Here’s what Taylor’s script was able to uncover:

  • REAIS: Taylor named this as the best starting word, with only 168 potential solutions having none of those letters.
  • BLAHS: Taylor named this the best word for eliminating most of the answers.
  • CENTU: This was the second-best word for eliminating most of the answers.
  • DOGGO: This was the third-best word for eliminating most of the answers.

How to Design Your Own Wordle Solver AI Bot

There are several other algorithms that people all over the world have developed to figure out the best starter words and create Wordle solvers. If you are a developer and want to build your own artificially intelligent bot that can solve Wordle puzzles with good accuracy, here’s how you can approach it:

Wordle Solver Algorithm Goal

There are two primary goals that we will have to consider while designing an effective Wordle solver bot:

  1. The algorithm should be fast. It should not take more than a few seconds to solve the puzzle.
  2. The algorithm should be able to solve the puzzle with 100% accuracy.

Wordle Solver Algorithm — The Wider Idea

Let the list of possible answers be: a1, a2, a3 … 

And the list of possible guesses be: g1, g2, g3 …

The idea is that we need an algorithm that could keep narrowing down the answers list until only 1 word remains in it.

Initially, all the words in the list are valid. With each guess, some words in the list are eliminated based on the feedback, and the list becomes shorter. Let's say we initially have the following matrix denoting the number of possible answers:

Every value in this matrix denotes the number of narrowed-down answers with each pair of the guess word and the answer word. Here's how:

  • If the guessed word is w1 and the answer also happens to be w1, then the size of the narrowed-down list of the number of possible answers will become equal to 1. That's why we have value 1 at the (w1, w1) cell. Similarly, we have 1 at (w2, w2), (w3, w3), and (w4, w4).
  • 5 at (w2, w1) denotes that if the guessed word is w1 and the answer is w2, then the size of the narrowed-down list will become equal to 5.

The smaller the size of the narrowed-down list, the higher our chances of getting to the right solution for the Wordle. Therefore, we need to keep decreasing the size of the narrowed-down list with each guess. We can consider two possible strategies for this:

  • Greedy-min-max strategy: This strategy chooses the word which minimizes the worst-case length of the narrowed-down answer list after making a guess. For example, in the above table, if we guess w1, the worst-case length of the narrowed list will be 8 (will happen in case the answer is w4).

    Similarly, the worst-case length of the narrowed list is 7, 5, and 10 if we guess w2, w3, and w4, respectively.
    Observe that guessing w3 at this stage will minimize the length of the narrowed list of answers in the worst-case. Therefore, this strategy will guess the word w3.
  • Average-minimize strategy: This strategy chooses the word that minimizes the average-case length of the narrowed-down list. The average length of the narrowed list if we guess w1, w2, w3, and w4 will be 5, 3.25, 3.5, and 5.75, respectively. Therefore, this strategy will guess the word w2 at this stage.

The algorithm that decides how to fill up the values in the matrix above is for you to interpret. Once you have the matrix, the best way is to test both the greedy-min-max as well as the average-minimize strategy and compare the mathematical results. 

This final testing of your solver will be very difficult to do on the official Wordle website as only one puzzle gets published on the website each day. You can test your algorithm for both of the strategies on the Word Master website, which allows you to make as many attempts as possible. 

We hope this article has given you some direction to get started with your Wordle solver. If you like creating puzzle solvers, you'll find this post on Sudoku Solver interesting. 

All the best and happy coding!

Join Interview Kickstart to Nail Your Next Tech Interview

Interview Kickstart helps software engineers land their dream jobs. We offer industry-best interview prep courses for high-demand domains such as Data Science, Machine Learning, and more

These courses are designed and taught by FAANG tech leads and hiring managers to help you get into FAANG+ companies. 

Sign up for our FREE webinar to learn more.



WEBINAR +LIVE Q&A

How To Nail Your Next Tech Interview

Hosted By
Ryan Valles
Founder, Interview Kickstart
Our tried & tested strategy for cracking interviews
How FAANG hiring process works
The 4 areas you must prepare for
How you can accelerate your learnings

Recent Articles

No items found.