18.5.12

Mastermind er også et spil?


Six-guess algorithm

The following algorithm solves the (six-color) game in six or fewer guesses. It has a general procedure and a few listed exceptions. In this section the six colours are referred to as letters a through f.
Divide the 1296 possible games into four categories:
  • 0 duplicates (e.g. abcd)
  • 1 duplicate (e.g. aabc)
  • 2 duplicates (e.g. aabb or aaab)
  • 3 duplicates (e.g. aaaa)
The general process is to list all the games that could be correct with the data so far. The list should be sorted by ascending number of duplicates and within each duplicate level alphabetically. Before guess 1, the list is all 1296 games; thus guess 1 is always "abcd." If the reply to guess 1 is "0 0," for example, then the list afterwards comprises the 16 games involving only e and f. Each subsequent guess is the first game remaining in the list, with the following exceptions:
  • Guess 2 is always "bcde"
  • Guess 3 is always "cdef"
  • If the list for guess 4 starts with a game on the left side of the list below, then use the game to its right instead:
    • "acfb" → "dcad"
    • "aebf" → "edfd"
    • "aefb" → "eacc"
    • "afbe" → "bfcd"
    • "bafe" → "eadc"
    • "beaf" → "edae"
    • "befa" → "eeda"
    • "eabf" → "fdfb"
    • "aadb" → "babd"
    • "abae" → "bbcc"
    • "aeaf" → "cffd"
    • "cafa" → "fdfa"
    • "aaee" → "dddf"