Mastermind or Master Mind is a code-breaking game for two players. The modern game with pegs was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. It resembles an earlier pencil and paper game called Bulls and Cows that may date back a century or more.
The iPhone chooses a pattern of four code pegs. Duplicates are allowed, so the iPhone could even choose four code pegs of the same color.
The player tries to guess the pattern, in both order and color, within ten turns. Each guess is made by placing a row of code pegs on the decoding board. Once placed, the iPhone provides feedback by placing from zero to four key pegs in the small holes of the row with the guess. A colored or black key peg is placed for each code peg from the guess which is correct in both color and position. A orange key peg indicates the existence of a correct color code peg placed in the wrong position.
If there are duplicate colors in the guess, they cannot all be awarded a key peg unless they correspond to the same number of duplicate colors in the hidden code. For example, if the hidden code is red-red-yellow-yellow and the player guesses red-red-red-yellow, the iPhone will award two colored key pegs for the two correct red, nothing for the third red as there is not a third red in the code, and a colored key peg for the yellow. No indication is given of the fact that the code also includes a second yellow.
Once feedback is provided, another guess is made; guesses and feedback continue to alternate until either the codebreaker guesses correctly, or twelve (or ten, or eight) incorrect guesses are made.
In 1977, Donald Knuth demonstrated that the it can solve any pattern in five moves or fewer :)