18 comments

[ 2.9 ms ] story [ 51.6 ms ] thread
I love stuff like this. It always tickles my brain to try and find the optimal way (or, as optimal a way as I can) of solving puzzles. Sometimes it's easy, sometimes it's really hard. Oftentimes you can get something decent with not too much effort, and the dopamine hit is great when you see it working
Really liked it. I'm curious about games for which the guesses are not always a valid solution but can contain special operators. For instance, add a state which is true for 2 different values in Secret Code : 1or2. The code won't contain it but it can be useful for getting more information at each step.
Really great article. Internalizing that a good realizable Mastermind strategy is to always eliminate the same number of possible solutions is a great way to internalize the value of information theory thinking. Getting hung up if it is exactly "plan k steps forward optimal" (i.e. fine details of the remaining possible cases) can be counter-productive.
Cool. Tiny tip, “Worlde” is obviously a typo for the popular puzzle.
I grew up with this game. It hurt my brain but in a good way. I think a lot of my problem solving and interest in coding stemmed from it.
The Kodak Research Labs (like Bell Labs) let their researchers play. In the 1960's my father (who later devised the Bayer filter for digital cameras) coded this algorithm for "Jotto" the 5 letter word version of Mastermind.

Computers were so slow that one couldn't consider every word in the dictionary as a potential guess. He decided empirically on a sample size that played well enough.

I became a mathematician. From this childhood exposure, entropy was the first mathematical "concept" beyond arithmetic that I understood.

This was my favorite game to play with my parents when I was growing up.
That reminds me, I wrote it for iPhone when it was released in 2007 - back then there was no App Store, so apps could only be written for browsers. I think I implemented it whenever I learned a new language. By the way, I noticed that Claude, ChatGPT, and DeepSeek - none of those LLMs can solve Mastermind. They get lost after a few iterations, no matter how good the prompt instructions are. Source: https://github.com/muquit/iphonemm - there is a link to play on that page.
You can ask them to write a script to solve it however and it is a trivial task for an LLM.
I play Mastermind with my kids. It hasn’t clicked quite yet with them but I’ve shown them my strategy of eliminating colors by making an entire row a single color successively. Either it’s not present or now you know how many of a particular color. Then you just need to figure out ordering. Again you can use a known “bad” color to avoid ambiguity of multiple white pegs
My grade school had a game club at lunch hour. Mr. Newton took time out of his day, every day for us. Still think about him and the many games he brought from his had personal collection. Not sure what the point of this message is other than that he will be remembered until the last time I think about mastermind, Pacific typhoon, star fleet battles, axis and allies and many others..
I don't know if you need "information theory" to do something that can be solved with grep.
I don't understand the point of this article, as it doesn't define an objective function. It just states a strategy that is only practically implementable for small board sizes (given the cited NP-completeness result) and then calls it good sans theorem or even conjecture.

I believe it is provably not the optimal algorithm for solving the problem under the minimax objective, and I have a hunch that (due to rounding issues) it is also not optimal for minimizing the expected number of guesses under even a uniform prior. So what does this actually accomplish?

Oh, I loved working on this problem years back.

My strategy was simulate my possible next guesses against all possible codes, then pick the option that had the highest number of possible outcomes (sometimes this strategy is called MaxParts). It looks like the author's approach works for similar underlying reasons.

Besides this, I applied some optimizations for the starting move, and some further optimizations on considering 'irrational' guesses -- e.g. choosing a code that had already been eliminated as a possibility, because it returned more information (this was rare, but possible).

I ran my code against all possible games of 4,6 mastermind (I win in an average of 4.2778 guesses), and found that some starting guesses were more optimal than others! The pattern "AABC" (e.g. red-red-yellow-green) was the best performer. Perhaps this is a way that the author can improve their algorithm just a tiny bit.

fascinating website bug: pop-up to select color in the last couple guesses is displayed below "6^4 = 1296" formula in the text below - so the pop-up closes when I hover over the numbers
I didn't back it with any formal reflection, but I played the game a bit with my daughter last year.

We had some fun and nice exchange around it, but closing all parties in just 4 rounds made it quickly boring.