Solving Wordle with Z3
typon.github.io
typon.github.io
Two young CS researchers took part in the competition after building their home-made algorithm (I suppose based on tree search) to find optimal words to search for, given the constraints. They learnt these optimal words/paths by heart before the show.
They never lost a game. Opponents scores were embarrassingly low, they actually broke the game. It was also very funny to watch because they spelled words that most people didn't know they exist.
I'll edit if I can find a video link (which is surprisingly struggling).
This kinda reminds me of the New Zealand Scrabble player who won multiple French World Scrabble Championships despite not speaking French. He just memorized the French Scrabble dictionary.
[1] https://en.wikipedia.org/wiki/Nigel_Richards_(Scrabble_playe...
https://okosjatek.cdn.shoprenter.hu/custom/okosjatek/image/d...
But in Mastermind, you for example aren't told which pins are in correct positions, whereas in Wordle you are told that.
and In November 2004, Michiel de Bondt proved that solving a Mastermind board is an NP-complete problem when played with n pegs per row and two colors, by showing how to represent any one-in-three 3SAT problem in it.
Obviously, I don't expect everyone to determine and memorize the information-theoretic optimal technique for extracting information from a word game or anything. But for Pete's sake, if you're going to be on the Wheel of Fortune, clock some time with one of the dozen or so computer or console implementations. If you're going to be on the Family Feud, take a moment to explain to funny Uncle Harry that saying the stupid-but-funny answer that popped into his head may cost him and four people who know where he lives a few thousand bucks. If you're going to play the old Concentration game, which was based on rebuses, spend a few hours brushing up on common rebus symbols and patterns.
(That's another show that, were it on today, would probably be broken by someone on the Internet. There is probably less than meets the eye when it comes to what can be done on a rebus. Someone could probably analyze the show's run and work out which are the most common syllables they can use, what is phonetically difficult to represent with rebuses, etc.)
ISTR that the Wheel of Fortune, for instance, edits out even more mistakes than you'll see on the show, which is plenty, according to one of the "behind the scenes" things. It isn't that hard, anyone can get it in 15 minutes or less, which suggests a lot of contestants come in with not even that much experience.
This is for many people the most bang-for-the-monetary-buck they will ever see in their lives. There are other things that will be more important, like having families, but monetarily, this is probably the most money-per-minute they will ever see. Put at least a bit of work into it!
I don't watch WoF a lot but you can also tell they're playing games with the most common letters after RSTLNE too... simply picking the next three consonants and the next vowel is a great way to lose.
And, I mean, yes, very stressful. But you might also be a bit less stressed if you prepared a bit more. Not relaxed, of course, but less stressed.
He used to be a reference librarian so he's good with facts, and does crosswords (cryptics) constantly so he knows pretty much every word.
I think the idea is calling python functions from SQL to check 'matched letter in wrong place'.
It may not be the best way, but it seems to lead to very clean, compact and understandable code. I have no background with Z3 (or any SAT solver for that matter) but I didn't have much trouble following the author's approach.
For yesterday's word, it yielded the following sequence of guesses: AESIR, DROPT, ABCEE, QUERY!
Most useful for us humans is that AESIR seems to be the best starting word.
Here is my java source code for this solver: https://pastebin.com/k1tTCyUR A bit obfuscated by some necessary optimziations.
I don't think anyone has released an 'optimal' player, yet. I imagine getting all target words (in the wordle dictionary) in four guesses is doable and three is probably not.
I've tried many, many approaches to get all in 4, and so far none work.
It is very nearly optimal (many of the parts are provably optimal, the only thing not yet optimal is doing an entire tree search, which is likely computationally impossible due to required tree size), using quite a bit of computation, precomputation, caching, etc., for the searching.
Oh, I also have a bot that solves Wordle in one move, every time.
Hint: the source code for Wordle is viewable from the page, and is easy to use to predict the word for each day.... But I've said too much now :)
Yeah, it might be bit cheeky to have a bot that guesses one word, and then gives you the correct answer and the date on which Wordle used or will use it.
Is the tree size still too big if you're only using Wordle's word list? (I'm almost interested enough to code something up, but asking you might mean I don't get fully nerd-sniped.)
Yes, it's what I use.
Wordle has ~2300 words as possible hidden words, ~12,000 more allowed as guesses. To get best scores you need to sample from all ~15k words.
So, to build a tree: for each hidden word (2k), pick a guess word (15k), gain knowledge (729 possibilities, but only one per hidden/guess pair). This reduces your possible hidden list to 70-1kish. Repeat..
Worst tree is 5 levels deep, mine averages 3 levels deep, pruning and memoization is nearly nonexistant (I checked).
You now have 30M first move outcome nodes, 2k of which are wins. After second move, you have a billion plus (I've sampled these to gain knowledge of what to expect). The next few rounds push the compute time into crazy realms of time (again, I've sampled to estimate sizes).
I'd guess given a lot of computing power, it could be done, since around 3-4 levels most of the games complete. But since you cannot easily store this tree, I gave up for now.
You should be able to store the tree with best move only at each node, which is good for gaming, but loses interest for statistical knowledge of the tree.
Good luck :) Nerd sniping complete :)
Wondering if you’re trying to split the pool 50-50 or more like 90-10.
Maybe I'm looking at it too much as some kind of decision tree but it looks to me like one, or at least something very similar. You don't want any branch to be too long.
So if S is in 90% of words, well you also reveal whether or not it’s in the nth location. Whereas an incorrect guess gives you no location information.
So, you’d want to guess the word that equally splits the word pool given both the letter and letter location (or just letter in a given location).
Whereas if there were a letter closer to occurring in only 50% of the pool, you at least eliminate half.
Does that logic make sense here or no? I’m thinking I’m missing something related to “maximum information gain”.
Trying to come up with a word that splits the list in half is actually ideal.
Search a word from previous answers, there are 2 arrays that the game uses to check with. Copy those and that’s the dictionary.
Spoiler alert: the first array is the answer array for even future wordles.
That's presumably the reason why I wouldn't want to view the source.
(I only got spoiled for tomorrow before I noticed.)
Take the future word list, and each day use tomorrow's word as much as can be naturally fit into normal conversation.
Then see if all of my friends start to score better, since they were primed.
(I am too protective of spoilers to actually do this, but still.)
There really aren't that many 5-letter words, so there's going to be a few specific combinations of two starting words that rapidly whittle the list.
XYLYL is the worst.
JSON.parse(window.localStorage.getItem("gameState")).solution