1A2B

  1. Create a program to randomly generate 4 distinct digits (the leading digit can be '0').
  2. The player input a 4-digit string to guess.
  3. After each guess, the computer shows a hint to inform the player how many digits are guessed correctly.
  4. When the digits are guessed correctly, the program prints out how many guesses are taken, and the program terminates.

The program may run as follows:
I am thinking of a 4-digit number. Try to guess what it is.
The clues I give are...
When I say: That means:
  A         One digit is correct and in the right position.
  B         One digit is correct but in the wrong position.

Guess #1: 1234
1A
Guess #2: 2222
1A3B
Guess #3: 5278
1A1B
Guess #4: 7290
1A2B
Guess #5: 9205
2A1B
Guess #6: 6209
3A
Guess #7: 5209
3A
Guess #8: 8209
4A
It takes you 8 guesses to find the answer.