Guess 1A2B

  1. Traditional exercise of 1A2B game requires you to write a program, which randomly generates 4 distinct digits for the user to guess.
  2. However, it is the era of AI (artificial intelligence) now. Let's write a program to give the computer some "wisdom". In this exercise you are required to write a program, which will guess the 4 digits you chose.
  3. The algorithm may look like:
    1. Generate a vector of permutations (0,1,2,3), (0,1,2,4), (0,1,2,5), ..., (9,8,7,4), (9,8,7,5), (9,8,7,6).
    2. The computer picks a guess from the above possible choices.
    3. After each guess, you will tell the computer whether its guess achieve "1A2B", "4A", or "0A". For convenience, you may also input in lowercase "1a2b".
    4. If "4A", the program ends.
    5. Otherwise, remove impossible choices and go to Step 2.
(9,8,7,6) -- 0a
(5,4,3,2) -- 1A2B
(5,3,4,1) -- 3B
(4,5,3,0) -- 1a1b
(4,1,5,2) -- 3B
(1,2,3,5) -- 3a
(1,2,3,4) -- 4A
Great.  I make it with 7 guesses.