Why You’re Likely To Solve Wordle (according to 100,000 Simulations) | by Daniel Tompkins | Jan, 2022

tl; DR: If you follow every hint you’ll always be left with only one word by your sixth guess…based on my 100,000 computer simulations

Daniel Tompkins
Screenshot of Wordle
import numpy as np
with open("wordlist_guesses.txt", 'r') as f:
all_words = f.readlines()
def score_word(chosen, guess):
score = [-1, -1, -1, -1, -1]
for i, w in enumerate(guess):
if w in chosen:
if w == chosen[i]:
score[i] = 1
else:
score[i] = 0
return score
def remove_words(score, guess, word_list):
to_remove = []
for i, word in enumerate(word_list):
for s, w1, w2 in zip(score, word, guess):
if s == 1:
if w1 != w2:
to_remove.append(word)
break
elif s == -1:
if w2 in word:
to_remove.append(word)
break
elif s == 0:
if w1 == w2:
to_remove.append(word)
break
elif w2 not in word:
to_remove.append(word)
break
word_list = list(set(word_list) - set(to_remove))
return word_list
def wordle(word_list):
count = 0
chosen_word = np.random.choice(word_list)
score = [-1, -1, -1, -1, -1]
left = None
while score != [1, 1, 1, 1, 1]:
count += 1
guess = np.random.choice(word_list)

score = score_word(chosen_word, guess)
if score == [1, 1, 1, 1, 1]:
left = len(word_list)
else:
word_list = remove_words(score, guess, word_list)
return count, left

Selected word: house (chosen from 12,972 words)Guess    Score              Words left
stent [0, -1, 0, -1, -1] 941
hexes [1, 0, -1, 0, 0] 6
horse [1, 1, -1, 1, 1] 2
hoise [1, 1, -1, 1, 1] 1
house [1, 1, 1, 1, 1] (it was the only option!)

Leave a Comment