Increase Speed of Wordle Bot (General For Any Programming Language)

Viewed 38

I am working on a Wordle bot to calculate the best first (and subsequent) guess(es). I am assuming all 13,000 possible guesses are equally likely (for now), and I am running into a huge speed issue.

I can not think of a valid way to avoid a triple for loop, each with 13,000 elements. Obviously, this is ridiculously slow and would take about 20 hours on my laptop to compute the best first guess (I assume it would be faster for subsequent guesses due to fewer valid words).

The way I see it, I definitely need the first loop to test each word as a guess. I need the second loop to find the colors/results given each possible answer with that guess. Then, I need the third loop to see which guesses are valid given the guess and the colors. Then, I find the average words remaining for each guess, and choose the one with the lowest average using a priority queue.

I think the first two loops are unavoidable, but maybe there's a way to get rid of the third? Does anyone have any thoughts or suggestions?

1 Answers

I did a similar thing, for a list with 11,000 or so entries. It took 27 minutes.

I did it using a pregenerated (in one pass) list of the letters in a word, as a bitfield (i.e. one 32 bit integer) and then did crude testing using the AND instruction. if a word failed that, it exited the rest of the loop.

Related