r/pythonhelp • • Jan 08 '22

Let's Solve Wordle

There is a game called Worlde where you have to guess the 5 letter word. I want to know if you can solve it for every answer after 3 guesses (so on your fourth guess).

  • There are 2315 possible answer words.

  • There are 12972 words you can use to guess.

Every guess gives you information on each letter:

  • Letter does not exist in word.

  • Letter exists but not in correct place.

  • Letter correct and in correct place.

My intuition tells me an algorithm should be able to know the word after 3 guesses every time.

But I'm not sure how to program it. Any ideas?

-----------------------

My thoughts are: you go through each possible starting word:

And for each answer, there will be a set of other possible answers.

So see if, with 2 additional guesses, you can always uniquely identify each of these possible other answers. So with a 2nd guess word, followed by a 3rd guess word, depending on the information gathered from the 2nd guess word.

So see if there is a 1st guess that, combined with 2nd and 3rd guesses you can always uniquely identify the Answer.

2 Upvotes

4 comments sorted by

2

u/skellious Jan 08 '22

you should learn regex (regular expressions).

they will be key to doing this efficiently.

then use the re module to filter the list to only those that match the regex.

you could also use it to generate the best guess each time (i.e. the guess that will eliminate the most words on average)

1

u/gwn81 Jan 08 '22

Not sure if you're just doing this for practice, but it's already been done https://github.com/yotam-gafni/wordle_solver

Worst-case performance, it needs 8 guesses to win, so it doesn't always win and there may be room for improvement, but it could be a good start/hint at least

1

u/CraigAT Jan 08 '22

Interesting that the GitHub link only has 2083 words.

1

u/CraigAT Jan 08 '22

With a combination of analysis, pre-calculation and clever decisions it may be possible.

Happy to play a sounding board over chat if you have some ideas, I have a few of my own, but I am probably not going to code something myself.

I have good idea how I would approach the task, with the first (and probably second word) being exploratory based on the full word list, then it may be a case of recursively trying educated guesses ( playing the odds) for the remaining letters.