GridPencil
04

Code Breaker

Find the hidden four-digit code in ten guesses, using the feedback after each attempt.

About Code Breaker

Code Breaker is a game of pure deduction, known to many people from a plastic board game with coloured pegs. The computer picks a secret code. You make a guess, it tells you how close you were, and you use that to make a better one.

How it works

There are 1,296 possible codes, since each of the four positions can be any of six digits. After every guess you get two numbers. One says how many digits are exactly right. The other says how many are the right digit in the wrong place.

The feedback never tells you which digits it is talking about. That is the puzzle.

Solving tips

Make your first guess informative. Something like 1 1 2 2 tests two digits at once and tells you how many 1s and 2s the code contains. Follow it with 3 3 4 4 and you will know the make-up of the code almost completely.

Treat a reply of "0 in place, 0 misplaced" as good news. It removes every digit in that guess from the puzzle.

Before each new guess, check it against all the earlier feedback. If your new guess were the real code, would your old guesses have received the replies they did? If not, it cannot be right, and there is no point trying it.

Change one thing at a time once you are close. If swapping two digits raises the "in place" count by two, you know both are now correct.

A careful player rarely needs more than six guesses. It is one of the purest thinking HTML5 games you can play, since luck matters only on the very first row.