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!
it's different in that you use colours instead of numbers and allows repeated colours in the solution, but I assume it has the same strategy (generally guess 1122, then 3344 etc until you know which numbers are in the solution, then try different permutations. I read somewhere that worst case scenario is 6 tries with the right algorithm but that doesn't apply here
– Slepz Jan 18 '16 at 20:37