Computer as Master Mind (1976) [pdf]
cs.uni.edu
cs.uni.edu
I think the reason it has captivated me for so long is because of the unexpected insight that choosing a known short-term failure or an increased chance of short-term failure (when optimizing for information gain) will result in quicker paths to your final goal AND decreased amounts of short-term failures.
My repo (currently being reworked) for simulating different strategies in hangman and battleship: https://github.com/chrisconley/hangman
I think I read some algorithm for solving mastermind; but never tried understanding mastermind. For the related game of Cows-and-Bulls, there is a elegant algorithm that goes on reducing the list of candidates at each turn. Starting with 9999 potential numbers seems like a lot, but that solution also quickly terminates (7 guesses max, I think).
Another way to optimize is for the avg number of guesses. The algorithm for this approach is to choose your next guess based on the guess that will give you the maximum amount of information gain (https://en.wikipedia.org/wiki/Entropy_(information_theory)#D...).
You can speed up the first step by realizing you don't need to test every code. E.g. 1122 and 1133 are essentially equivalent. You only have five unique choices for the first step 1111, 1112, 1122, 1223, 1234. If you run all codes against those 5, you'll get the first step. Continue doing it for the rest and you'll get the other steps.