News for hackers. Stuff that matters.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by npinsker on Sunday January 23, 2022 @04:35PM (#30050664)
I wrote a solver a few weeks ago that solves easy mode in 3.45 guesses and hard mode in 3.55 guesses. Rather than using heuristics, it explored a large portion of the game tree (with a little pruning) and I'm hopeful that it's optimal. Interestingly, the EV-optimal hard mode strategy takes 3.52 guesses on average, but requires 7 guesses a tiny fraction of the time, so I instead exposed the best strategy that always requires 6 or fewer guesses.

If you're interested, you can play with it here: http://www.npinsker.me/puzzles/wordle/ and the source (written in neophyte's Rust) is here: https://gist.github.com/npinsker/a495784b9c6eacfe481d8e38963...

(edit: It's posted elsewhere in the thread, but this is actually not optimal and someone else achieved better results! http://sonorouschocolate.com/notes/index.php?title=The_best_...)

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by hgibbs on Sunday January 23, 2022 @04:52PM (#30050843)
As a point of curiosity, what do you mean by optimal?

To me, I can see at least two (potentially different) cost functions that a Wordle strategy can aim to minimise. Firstly, you can try to minimise the expected number of guesses, and secondly you can try to minimise the expected number of guesses conditional on never losing the game. In principle you could optimise for the first but not the second by allowing a small list of hard words to take > 6 guesses on average.

Part of my point is the lack of an absolute definition of optimal: strategies are only optimal up to the specified coat function.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by svat on Sunday January 23, 2022 @06:48PM (#30051941)
IMO, never losing the game is the bare minimum for any reasonable cost function: never take > 6 guesses. Beyond that, you can have different optimization functions based on whether you're trying to minimize the worst-case depth of the decision tree (number of guesses) for each position, or the average depth, or some other reasonable function of the distribution over number of guesses.

Although you could have arbitrarily many cost functions, a fairly general class is the following: pick some nonnegative constants (w1, w2, w3, w4, w5, w6, w7), and for a certain strategy, define the cost as:

    w1*n1 + w2*n2 + w3*n3 + w4*n4 + w5*n5 + w6*n6 + w7*n7
where nk (for 1≤k≤6) is the number of hidden (solution) words for which the strategy takes n guesses, and n7 is the number of words for which the strategy loses the game. Then,

• Setting w7 infinite / very high is a way of encoding the condition that you not lose the game. (You can set it finite/small if you don't mind occasionally losing the game for some reason!)

• Setting w1 = 1, w2 = 2, …, w6 = 6 will simply minimize the average number of guesses,

• Having them grow exponentially, e.g. setting wk = c^(k-1), where c is some constant larger than 12972 (the number of acceptable guess words) will make sure that the minimal-cost strategy first minimizes the maximum number of guesses, then break ties by having the fewest words take that many guesses, and so on.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by tshaddox on Sunday January 23, 2022 @09:14PM (#30052889)
> IMO, never losing the game is the bare minimum for any reasonable cost function: never take > 6 guesses.

I wouldn’t think so. If I get 99.9% of rounds correct with 3 guesses (and fail to find a solution to 0.1% of the rounds), and you get 100% of rounds with 6 guesses, I’d say I’ve soundly defeated you 99.9% of the time.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by svat on Sunday January 23, 2022 @10:51PM (#30053541)
Right, that point of view makes sense if you imagine two players separately playing Wordle and comparing their results, and indeed that's what the OP may have been thinking. But as far as I know, Wordle is primarily a game for one player to play against the computer, where eventually getting to the word (or not) is the most prominent outcome (the only notion of "win" or "defeat" in the game itself), and solving it in fewer guesses is just a bonus. But sure, if you don't care about occasionally losing, you can just set an appropriate weight for w7 within the same family of cost functions.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by tshaddox on Monday January 24, 2022 @01:09PM (#30061465)
Indeed, it’s essentially a single player game, but we’re talking about which bot a player would want to use which is inherently a notion of bots competing against each other.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by rob74 on Monday January 24, 2022 @03:56AM (#30055015)
If you look at the failed attempts in the article, you'll see it's not so easy to get 100% correct with 6 guesses. For example:

SLATE, CRONY, HOUND, BOUND, POUND, MOUND (correct: WOUND)

SLATE, SHARE, SHAME, SHAPE, SHAKE, SHADE (correct: SHAVE)

...so sometimes even if it gets 4 of 5 letters right on the second try, it still has too many options left. Of course in cases like this it could go "one step back" and try a word with (most of) the letters that are different between these words (HBPMW or MPKDV). So try different words until the number of options is narrowed down sufficiently.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by balls187 on Sunday January 23, 2022 @11:34PM (#30053787)
> I’d say I’ve soundly defeated you 99.9% of the time.

Except it wouldn't be 99.9% of the time. Just the games were you guessed fewer than GP.

GP's solver would expect to guess the correct word 100% of the time in fewer than 6 guess, but not that it would always take 6 guesses.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by tshaddox on Sunday January 23, 2022 @11:41PM (#30053817)
I was saying if you hypothetically got every correct guess in exactly 6 tries. You would pass the suggested “bare minimum” while my 99.9% strategy doesn’t, yet I claim my strategy is better.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by guipsp on Monday January 24, 2022 @04:09AM (#30055086)
For some value of better, sure.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by tshaddox on Monday January 24, 2022 @01:03PM (#30061364)
Sure, where "some value of better" is "wins in the overwhelming majority of rounds."
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by divbzero on Monday January 24, 2022 @12:01AM (#30053904)
> never take > 6 guesses

I suspect that with most languages it’s impossible to achieve 100% win rate for five or more letters. So w7 should be by far the largest weight but I don’t think it can be infinite.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by rik2 on Thursday January 27, 2022 @06:41PM (#30108688)
I suspect the opposite. While the theoretical number of combinations is huge, the amount of information given by each guess grows faster than the number of real words of longer lengths.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by furyofantares on Sunday January 23, 2022 @05:02PM (#30050956)
They specified that in the post, they were able to constrain to a strategy that guarantees 6 or fewer and then optimize for EV to get 3.55, but could get down to 3.52 by allowing some small number of words to take more than 6.

I would be interested to know if 6 is the lowest you can constrain it. Can you guarantee a solution in 5, and if so what is the best EV with that constraint?

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by npinsker on Sunday January 23, 2022 @05:15PM (#30051062)
Yes, you can -- I believe the EV was around 3.47 for that. The "greedy" strategy (minimizing the worst-case size of the largest set) also ends up using at most 5 words.

Perhaps unsurprisingly, you can't guarantee at most 4 words.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by Sesse__ on Sunday January 23, 2022 @05:29PM (#30051199)
You can get EV of 3.46393 with a guaranteed maximum of five tries. (I don't know whether this bound is tight.)
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by pxx on Sunday January 23, 2022 @06:08PM (#30051581)
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by Sesse__ on Sunday January 23, 2022 @06:19PM (#30051671)
Good to know.

Another possible question is: What is the best strategy minimizing (at any point) _first_ the maximum number of tries, and second the EV (average number of tries over all possible words)? That's subtly different from either answer.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by hervature on Sunday January 23, 2022 @05:32PM (#30051228)
Funnily enough, I think neither of those notions are the correct thing to optimize. For me, you want to minimize the maximum number of guesses. This leads to an equilibrium. Otherwise, your opponent can just abuse your strategy.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by hgibbs on Sunday January 23, 2022 @06:55PM (#30051997)
My point is exactly that though - the choice of cost function is subjective. There is no best cost function, just a mapping from costs functions to optimal strategies.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by hnkain on Monday January 24, 2022 @06:02AM (#30056019)
The (exact) optimal EV-minimizing strategies (assuming each target word is equally likely) always solve in 5 of fewer guesses in normal mode, and always solve in 6 guesses in hard mode. If you wish to guarantee 5 guesses in hard mode, there's a different (optimal) strategy with slightly higher EV. See: http://sonorouschocolate.com/notes/index.php?title=The_best_...

I don't think a maximum-number-of-guesses optimizer leads to an equilibrium (if you mean Nash equilibrium), assuming you're playing the game where the score of the game for the setter is the number of guesses. In particular, if the solver's strategy is deterministic, the setter will always pick one of the words that needs 5 guesses. There's no reason to think the nash equilibrium can be easily found.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by noxvilleza on Sunday January 23, 2022 @06:34PM (#30051810)
Adversarial strategies are another type of problem entirely (as in, if you're playing Word Mastermind). Wordle is a 1-player game, so I find hgibbs's comment totally reasonable. I would think that 'optimal' is more accurately his second definition - minimizing avg guesses but always winning (as in, losing is +inf guesses).
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by pxx on Sunday January 23, 2022 @05:44PM (#30051333)
Isn't that just #2, but changing the definition of losing to be the least number of rounds where you can always win (which for Wordle is 5)? These small changes to the definition don't seem to change ev (or the code needed to generate it) that much.

If you don't care about optimizing the EV at all, the greedy tree already has the property you're interested in.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by eru on Sunday January 23, 2022 @11:03PM (#30053610)
What do you mean by opponent?

The entity choosing the word in a game like Wordle or Hang Man is more like the dungeon master in a game of D&D than an opponent in the traditional sense? They are there to help you have fun.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by tshaddox on Sunday January 23, 2022 @09:11PM (#30052868)
If two players are competing in a single round of wordle, then surely the player who guesses the correct word in the fewer number of guesses wins, right? Then it seems natural to say that the better of two players is the one with the most wins after playing all possible rounds.

The only problem is that I think this definition leads to the possibility of non-transitivity, where A beats B, B beats C, and C beats A.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by ycombobreaker on Sunday January 23, 2022 @06:53PM (#30051984)
I've seen a number of solvers; but my partner has forbidden me from writing one, forcing me to do everything in wetware. 3-4 guesses seems right intuitively. I saw some speculation that the dictionary was well-known, is that true?

Seems to me that the problem as-stated allows the guesser to discover a nonword "for free", but otherwise expects the dictionary to be "all five letter words" which is much larger than the real solution space. Though, maybe in practice that doesn't change the solvability by much.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by kevlened on Sunday January 23, 2022 @07:01PM (#30052047)
The wordlist is more than well-known, the word for each day is predetermined. The entire game runs in the browser and the selected word is based on the date. Here’s a quick script based on any date you select: https://codepen.io/kevlened/full/NWaOmPw
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by tomlockwood on Sunday January 23, 2022 @07:25PM (#30052167)
This program actually inadvertently created a quite philosophical discussion amongst my friends! Some of them contended that writing a program to solve wordle sucked the joy out of the process of solving it, even if I solved the puzzle myself, first.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by moritonal on Monday January 24, 2022 @07:16AM (#30056720)
I once caused a vague division in my secondary school by writing a (looking back now) horrendously hacky OCR solver for our "world maths day" challenge.

Literally half the teachers thought it was cheating and I should be punished, whilst the other half thought (because I hadn't abused it to win prizes) that it showed a creative use of more modern skills to make up for my renowned weak mental-math.

I saw the joy in writing the solver as much more interesting than the math. Same way I can't focus on sudoku given I always try to "solve" solving it.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by ycombobreaker on Sunday January 23, 2022 @07:49PM (#30052306)
Yes it's interesting, precisely because it's intuitively "solvable" by machines. There's joy in solving by hand, and joy in creating a solver, but probably no joy in running your solver every day and sharing with your friends. Because every decision is some maximum-likelihood estimate, there's no tension or drama in the sequence of guesses.

In fact, simply the act of creating an infallible solver (100% likelihood of 6 guesses or less) demonstrates the futility of competing with their soft, fleshy skills.

I do think any solver that uses the solution-set is "cheating", but I suspect it makes little difference in the total solution (like... 2-3 bits of additional information needed, just a fraction of a round).

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by eru on Sunday January 23, 2022 @11:06PM (#30053625)
You might find some enjoyment in writing solvers that compete with your friends' solvers?

You could either compete on number of guesses. Or you could fix the hardware (eg a Famicom), and compete on runtime?

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by tomlockwood on Sunday January 23, 2022 @04:40PM (#30050725)
Oh dang! I was guessing that the optimal approach would be under 3.5 for easy mode, but was expecting it to be closer to 3! Amazing work. My next go at the problem is in Rust, which I am a total newcomer to. Thanks for sharing!
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by theolivenbaum on Sunday January 23, 2022 @05:26PM (#30051173)
Nice! I was wondering almost the same thing this morning while my wife was playing Wordle - ended up coding an assistant to help you choose the optimum words.

If anyone wants to check it out, I published it here https://curiosity.ai/wordle/ - source code is also available here https://github.com/theolivenbaum/wordle-assist.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by bscphil on Monday January 24, 2022 @01:23AM (#30054257)
If you just brute force solve with greedy search (always pick the word that results in the highest average reduction in remaining possible words), you get a solution with an average of 3.47. Even only guessing words on the primary word list (which Wordle uses to pick the word of the day) you can get 3.51. That's as far as I've chased the problem.

I'm surprised to hear that optimal play only gets you 3.4212 (according to the link you posted).

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by forrestthewoods on Sunday January 23, 2022 @07:22PM (#30052156)
Neat!

The graph of every possible game for Hard mode should be pretty tractable. Sounds like you wrote almost exactly what I started but have been too lazy to finish.

> but requires 7 guesses a tiny fraction of the time, so I instead exposed the best strategy that always requires 6 or fewer guesses.

That's awesome. My question is "what is the minimum number of guesses to solve every word while guaranteeing it never loses". For hard mode I'm pretty sure this can be provably brute forced. Easy mode requires enough pruning I'm not sure it can be proved.

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by stavros on Sunday January 23, 2022 @05:05PM (#30050980)
That looks great! It would be very interesting to see the set of words "left" after a guess, too.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by desbo on Sunday January 23, 2022 @06:10PM (#30051592)
This is great. But it seems to fail with words containing repeat letters, for example, with my word as BOOKS, not on hard mode:

SOARE JUMBY BOOST (at this point, it claimed to have won!)

Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by pxx on Sunday January 23, 2022 @06:24PM (#30051723)
books isn't a valid solution. it's on the guesslist but not the wordlist.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by mrb on Sunday January 23, 2022 @08:15PM (#30052494)
Correct. In fact, thousands of plural words are allowed as guesses, but the solution will never be plural. Source: I grep'd the lists of solutions and authorized guesses.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by eco on Sunday January 23, 2022 @10:35PM (#30053434)
I used the combined solution and valid word list when I was playing around with a program to find good starting words. Feels too much like cheating otherwise.
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by Humphrey on Sunday January 23, 2022 @06:26PM (#30051740)
It fails with the word "frogs", as it tells me it is "gross"
Re:Solving Wordle in 3.64 guesses on average, 99.4% of the time by nerdo on Monday January 24, 2022 @04:02AM (#30055049)