Free video project · Intermediate
Wordle and a Wordle solver 🟩
The Wordle checker with the double letter rule done properly, then a solver that plays by itself by keeping only the words that still fit.
The video is out Tuesday 24 November at 6pm.
The code from the video
# Wordle: a checker and a solver
WORDS = ["crane", "slate", "pious", "about", "flint", "robot", "mango", "spoon", "ghost", "sport",
"short", "store", "stork", "storm", "sweet", "tower", "plant", "proud", "brave", "chess"]
def score(guess, answer):
result = ["."] * 5
left = list(answer)
for i in range(5):
if guess[i] == answer[i]:
result[i] = "G"
left.remove(guess[i])
for i in range(5):
if result[i] == "." and guess[i] in left:
result[i] = "Y"
left.remove(guess[i])
return "".join(result)
def solve(answer, first="crane"):
possible = WORDS.copy()
guess = first
for turn in range(1, 7):
result = score(guess, answer)
print(turn, guess, result)
if result == "GGGGG":
return turn
still = []
for word in possible:
if score(guess, word) == result:
still.append(word)
possible = still
print(" ", len(possible), "words left")
guess = possible[0]
solve("storm")
Run it in your browser with nothing to install, right here on this page.
Make it your own
- Make it playable: you type guesses and see coloured squares.
- Pick the solver's next guess by which letters are commonest in the words left.
- Test every starting word and find the one that solves fastest on average.
Skills: strings, lists, loops, functions