What’s the Best First Word for Wordle? | by Anna Azzam | Jan, 2022

tl; DR: The best starting word for Wordle is 'crate'. Read below to find out why!

Anna Azzam
Best Starting Word for Wordle

Wordle is an online puzzle game that has taken the world by storm. Every day, Wordle gives its players a new word to guess, and players are given six guesses to find the answer. Due to the popularity of the game, many people have been debating whether there is a specific “best first word” that will increase their chances of winning puzzles in the fewest number of steps. In this blog, I will show you a basic algorithm I wrote to try to answer this question!

The first step is To build a repeat function of the game checker. In Wordle, when you guess a word, it will tell you how close your word is to the answer using three colors – grey, yellow and green.

As an example, suppose that answer is being grave, and yours guess is being large , wordle will return something like this:

the meaning:

  • l not in the word
  • aAnd r , And g They are in the word, but in the wrong position
  • e In the word and in the correct position

To jot this down, I added the result type type:

type Result = 'correct' | 'exists' | 'absent';

Then I wrote a file evaluateGuess The way you take in guess And answer, returns an array of Result For each letter in the guess. Here is the job:

The next step was to build an algorithm that plays the game, by suggesting the next guess based on the current game state, and then calling evaluateGuess To determine the state of the new game.

Get all 5 letter words

Before writing the algorithm, we need a set of 5 letter words to choose the next guess among them. Fortunately, I found the word set that Wordle uses by viewing their source code:

Wordle source code

Next guess suggestion

Next, I wanted to write an algorithm that takes the current game state, and returns a suggestion for the next guess from the word list. The current game state can be represented as:

  • The messages we already know exist correct, which can be represented as(string | undefined)[]
  • The messages we already know exist existing, which can be represented as a map of <الأحرف الموجودة المعروفة> to <مواقع غير صحيحة معروفة>, for example { [k: string]: number[] }
  • The messages we already know exist absent, which can be represented as string[]

An example of a game state could be:

currCorrect: ['s', undefined, undefined, 'r', undefined],
currExisting: { 'a': [1], 'e': [1, 2] },
currAbsent: ['x', 'c', 'f', 'o', 'w'],

Once I select the game state types, I want to write a file makeNextGuess Which way:

  • Chooses a random word from the group of words (the group of words is shuffled randomly to prevent always starting from the letter a)
  • To check if a word is appropriate given the current game state (ie it doesn’t have any characters in the . format currAbsent)
  • Returns the first word that matches this criteria as the suggested guess

Here’s how:

game runner

Now that I have a way to make the following guess, I want to write a game runner:

  • accept answer and firstGuess
  • alternate calling evaluateGuess And makeNextGuess Even guess === answer
  • Displays a list of guesses taken by the algorithm to arrive at the answer

Here is an example of the expected output for firstGuess: 'share'And answer: 'hello'

Example output for “autorunGame”

Here’s how:

Now that we have an algorithm that automatically runs the game due to the extension firstGuess And answer, I can use this to write a findBestFirstWord Which way:

  • calls autorunGame With each word in the group versus every other word
  • Repeats these calls 10 times for accuracy
  • for every firstGuess, calculate an average The number of guesses to find the answer

Once we have the average number of guesses for each word, find the word with lowest average.

Here is the algorithm:

From running this algorithm, the best first word in Wordle was…. crate!

It is worth noting that there are several ways in which this algorithm can be improved. Different articles offer different strategies for finding the best first word, such as counting the most common letters and their frequencies.

Thanks for reading!

Leave a Comment