统计方面的,大致要求如下:
Exercise 2: Mastermind
Mastermind is a code-breaking game in which there are two players: the codemaker and the code-breaker. At the start of the game, the code-maker determines a secret code consisting of four numbers, each number being contained in the set A = f1; 2; 3; 4; 5; 6g. The code-breaker then tries to guess the code providing a four number sequence using the set A. The code-maker then gives feedback using black
and white pegs. For each number that is guessed correctly (i.e. being the correct number in the correct position), one black peg is provided. The corresponding numbers in the secret code and in the guess are \used up". For each of the other guesses, a number of white pegs is provided in the following iterative process:
It is decided whether the number guessed corresponds to one of the numbers in the secret code. If so, one white peg is added and the number in the guess and in the secret code are used up. One then continues with the next remaining number in the guess and the remaining numbers in the secret code to add further white pegs (if any). Once the feedback is provided, the code-breaker produces the next guess and triggers the next round of feedback. The process continues until the code-breaker has found
the secret code. To understand the feedback process and the notion of \used up\ numbers, consider
the following examples:
1. Let the true code be 1; 2; 4; 6 and the guess be 1; 2; 4; 6. In this case the feedback consists of four black pegs.
2. Let the true code be 1; 2; 4; 6 and the guess be 1; 1; 5; 5. In this case one black peg is provided for getting the rst number right. This uses up the rst number, so the remaining numbers are 2; 4; 6 in the true code and 1; 5; 5 in the guess. So, no further pegs are awarded.
3. Let the true code be 1; 2; 4; 6 and the guess be 1; 1; 2; 5. In this case one black peg is provided. The remaining numbers are 2; 4; 6 for the true code and 1; 2; 5 for the guess. So a further white peg is awarded so that overall we get one black peg and one white peg.
4. Let the true code be 1; 1; 2; 3 and the guess be 4; 4; 1; 4. In this case, only one white peg is awarded, even though the code contains the number one several times.
5. Let the true code be 1; 2; 3; 4 and the guess be 6; 1; 1; 1. In this case only one white peg is awarded even though the guess contains the correct number one several times.
6. Let the true code be 1; 1; 2; 2 and the guess be 3; 3; 1; 1. In this case two white pegs are awarded.