The above image was the second image generated by Stable Diffusion when inputted the prompt “Wordle Simulator”.
Once again, it was only after I had established (and finished coding) my last strategy that I realized its flaws. I realized that only looking one level deep to find the optimal first word would result in a word far from optimal, so I had to, once again, rethink my strategy. I decided that to really find the optimal word, I would need to solve the problem directly. To do so, I devised a strategy based on the following logical progression:
Best Starting Word > Fastest Wins > Less Guesses > Less Possibilities
Essentially, to find the best word, I would have to find the word that most efficiently eliminated possibilities. However, thinking a little more into the subject, I found it very difficult to pinpoint exact values for what percentage of words eliminated was “optimal”– the information needed was dependent on information that would be produced. I therefore decided that the best course of action would be to program a Wordle-solving bot, and use information based on the mean number of guesses the bot takes for every combination of two words to deduce which word on average requires the least steps, and is therefore the best word.
But first, I needed to have the program simulate Wordle internally, so that it could later be solved. The main component in building this game was the function that would mark letters as Gray, Yellow, or Green, so I decided to program a function that would take three inputs: the guess, the answer, and the list to choose words from. This function would output a list, which would contain all words satisfying the colored conditions. The following code sets up the framework for the function. “word” is the answer, “word_guess” is the word that would be inputted into the game, and “word_dictionary” is the outputted result:
def remove_words (word, word_guess, word_dictionary):
for pos in range(0, 5):
return word_dictionary
From here, I started adding in the logical statement for Green:
#Green
if word_guess[pos] == word[pos]:
for wordguess2 in list(word_dictionary):
if wordguess2[pos] != word_guess[pos]:
if wordguess2 in word_dictionary:
word_dictionary.remove(wordguess2)
This code first checks if a certain letter in “word_guess” appears in the same position in “word”. It then runs through all words within word_dictionary (via repeated “wordguess2″‘s), and checks if those words have the same letter in the same position. If they do not, they are removed from “word_dictionary.
Now, for the Yellow:
#Yellow
if word_guess[pos] in word and word[pos] != word_guess[pos]:
for wordguess2 in list(word_dictionary):
if word_guess[pos] not in wordguess2 or word_guess[pos] == wordguess2[pos]:
if wordguess2 in word_dictionary:
word_dictionary.remove(wordguess2)
This code first chooses a letter from “word_guess”, and checks if it appears in “word”. If it does in a different position, it runs through all words within word_dictionary (via repeated “wordguess2″‘s), and checks if those words have the same letter in a different position. If they do not, they are removed from “word_dictionary”.
Finally, for the Gray:
#Gray
if word_guess[pos] not in word:
for wordguess2 in list(word_dictionary):
if word_guess[pos] in wordguess2:
if wordguess2 in word_dictionary:
word_dictionary.remove(wordguess2)
This code first checks if each letter in “word_guess” appears in “word”. If it doesn’t, it retains that letter, and runs through all words within word_dictionary (via repeated “wordguess2″‘s), checking if that letter is contained within those words. If so, they are removed from “word_dictionary”.
So at the end, our final function looks like this:
def remove_words (word, word_guess, word_dictionary):
for pos in range(0, 5):
#Green
if word_guess[pos] == word[pos]:
for wordguess2 in list(word_dictionary):
if wordguess2[pos] != word_guess[pos]:
if wordguess2 in word_dictionary:
word_dictionary.remove(wordguess2)
#Yellow
if word_guess[pos] in word and word[pos] != word_guess[pos]:
for wordguess2 in list(word_dictionary):
if word_guess[pos] not in wordguess2 or word_guess[pos] == wordguess2[pos]:
if wordguess2 in word_dictionary:
word_dictionary.remove(wordguess2)
#Gray
if word_guess[pos] not in word:
for wordguess2 in list(word_dictionary):
if word_guess[pos] in wordguess2:
if wordguess2 in word_dictionary:
word_dictionary.remove(wordguess2)
return word_dictionary
This conveniently returns a dictionary with all the remaining possibilities, given the information we already have. Finally, to make it user interactive, we use the following code to input guesses and the word we are trying to guess:
for i in range (0,7):
if (len(result) == 1):
break
word_guess = str(input("What's your next guess?"))
print("Guess",i+2,":",word_guess)
result = remove_words(word, word_guess, result)
print(len(result), result)
Here is an example run, where I, with the program’s help, try to find thw word “apple”:

