Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to solve the "Mastermind" guessing game?
    text
    copied!<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not which) of the colours you guessed were the right colour in the right place ["blacks"] and how many (but not which) were the right colour but in the wrong place ["whites"]. The game ends when you guess correctly (4 blacks, 0 whites).</p> <p>For example, if your opponent has chosen (blue, green, orange, red), and you guess (yellow, blue, green, red), you will get one "black" (for the red), and two whites (for the blue and green). You would get the same score for guessing (blue, orange, red, purple).</p> <p>I'm interested in what algorithm you would choose, and (optionally) how you translate that into code (preferably Python). I'm interested in coded solutions that are:</p> <ol> <li>Clear (easily understood)</li> <li>Concise</li> <li>Efficient (fast in making a guess)</li> <li>Effective (least number of guesses to solve the puzzle)</li> <li>Flexible (can easily answer questions about the algorithm, e.g. what is its worst case?)</li> <li>General (can be easily adapted to other types of puzzle than Mastermind)</li> </ol> <p>I'm happy with an algorithm that's very effective but not very efficient (provided it's not just poorly implemented!); however, a very efficient and effective algorithm implemented inflexibly and impenetrably is not of use.</p> <p>I have my own (detailed) solution in Python which I have posted, but this is by no means the only or best approach, so please post more! I'm not expecting an essay ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload