Mastermind Solver
- Uses six letters instead of six colors.
- Input a puzzle (e.g. "bfab") and press <Enter>.
- The solver starts by picking a random letter and its succeeding
neighbor. Each letter is guessed twice.
- After the answer is computed, pressing <Enter> again will solve
the same puzzle again. If a different random letter is chosen, the
answer will take a different path.
The solver uses the following four rules:
- If "black + white = 0", then each letter in the guess should be eliminated
from every slot.
- If "black = 0", then each letter in the guess should be removed from the
position it holds in the guess.
- If "black + white = 4", then start guessing permutations of the current
guess.
- A potential guess is invalid if it contradicts feedback from any previous
guesses.
The implementation is a state machine with four states:
- GuessOne - pick a randow letter and its succeeding neighbor
- GuessTwo - pick the next two neighbors
- GuessCompute - cycle through all remaining combinations (like an odometer),
applying rule 4 before submitting each guess
- GuessPermute - cycle through all permutations,
applying rule 4 before submitting each guess
GuessOne and GuessTwo issue a single guess each. GuessCompute keeps guessing
until rule 3 applies and GuessPermute is made the current state.