This question already has an answer here:
- Clever ways to solve Mastermind? 7 answers
There is a popular game called Mastermind in which one player guesses another player's secret sequence - it could be a word, some colors, or numbers. The guesser says a possible sequence, and they get back the number of correct numbers in the right spot and the number of correct numbers in the wrong spot. Here we will be playing Mastermind with 4-digit numbers.
Here is an example game with the answer "4560".
You start with 1234 and get the response "-1"; that means one digit is correct but in the wrong location. You guess 3465 and get "-2 +1"; that means two digits are in the wrong location and one digit is in the correct location. The other digit isn't part of the number at all.
The game continues:
1234: -1 3465: -2 +1 4503: -1 +2 4560 +4 (4 tries and win!)
You are very smart, so as soon as you get enough information you'll be able to guess the number instantly, but the problem is that you are the unluckiest person alive, especially at guessing numbers. So, in the worst case scenario, how many guesses do you need to find your opponent's number?
Keep in mind that 4-digit numbers can't start with 0!