Skip to content
Thinking Games
EN
Deduction

Crack the Lock: how to solve a code-breaking puzzle

In a code-breaking puzzle you see a few attempts at a secret code and, for each one, how many digits are right and in place and how many are right but misplaced. From those answers alone, exactly one code is possible. This guide explains how to read each answer, how to combine several, and how to reach the code without trial and error.

The rules, as the app states them

Work out the code from the attempts already made.

  1. No digit repeats in the code. Each attempt shows how many of its digits are in place, and how many are in the code but misplaced.
  2. Tap a position on the lock, then a digit. Position 1 is the one on the left of the screen.
  3. Under “Possible digits”, tap a digit to cross it out or mark it as sure. Those are only notes. The lock opens when your code fits every attempt.

What a code-breaking puzzle is

The idea comes from Bulls and Cows, an old pencil-and-paper game for two. One player writes a secret number with no repeated digits. The other makes guesses and is told, each time, how many digits are correct and in the right position (bulls) and how many are correct but in the wrong position (cows).

The puzzle version removes the guessing. Somebody has already made the attempts, and they were chosen so that their answers leave a single code. Your job is the part that matters in the game: working out what the answers prove. It is the format of the riddles with a padlock and five lines of clues that circulate online, built here so that every step can be justified.

The rules in detail

The code has three or four positions, and no digit repeats in it. The attempts do not repeat digits either. Each lock tells you which digits exist: 1 to 6 in some, 0 to 9 in others.

Every attempt comes with two numbers:

  • In place: how many of its digits are in the code and in that same position.
  • Misplaced: how many of its digits are in the code, but in a different position.

Three details are easy to overlook. The answer gives counts, never which digits they refer to. A digit is counted once: if it is in place, it is not also misplaced. And the two numbers added together are the number of digits of that attempt that belong to the code, wherever they go.

In Crack the Lock you tap a position and then a digit; position 1 is on the left. Under Possible digits you can cross a digit out or mark it as sure. Those notes are for you and decide nothing: the lock opens when the code you have entered fits every attempt.

Where to start: the attempt where nothing is correct

An attempt with zero in place and zero misplaced looks like a wasted try and is the most useful line on the board. All of its digits are out of the code. Cross them out in your notes.

With six digits and a three-digit code, that single line finishes half the job: if three digits are out, the code is made of the other three, and only their order is left to find. When no attempt says "nothing is correct", start with the one whose two numbers add up to the most or to the least. Extremes say more than middles.

Five techniques for reading the answers

1. Add the two numbers

In place plus misplaced is how many digits of the attempt are in the code. If an attempt of three digits scores a total of three, you know the full set of digits. If it scores one in a three-position lock with digits 1 to 6, then two of the three digits it did not use are in the code.

2. Zero in place bans every position

When nothing is in place, none of the attempt's digits can go where the attempt put it. An attempt 2 6 3 with zero in place tells you that 2 is not first, 6 is not second and 3 is not third, whether or not they are in the code.

3. Carry what you know into the next attempt

Once a digit is crossed out, remove it mentally from every attempt. An attempt with "one misplaced" and two digits already crossed out is no longer vague: the misplaced digit is the third one, and it does not go where that attempt has it.

4. Compare attempts that share digits

If two attempts differ in a single digit and their totals differ, the changed digit explains the difference. One of the two digits is in the code and the other is not, and the totals say which.

5. Suppose and contradict

When an answer leaves two possibilities ("one of these two is in place"), assume the first and follow it. If it forces a digit into a banned position, or leaves a digit with no position, the first was false and the second is true. This is a proof, not a guess, as long as you follow both branches to the end.

A worked example with three positions

The lock uses the digits 1 to 6 and the code has three positions. These are the attempts already made:

Three attempts and their answers.
AttemptIn placeMisplaced
1 3 500
2 6 302
4 2 111
  1. Nothing is correct in 1 3 5. The digits 1, 3 and 5 are out. Only 2, 4 and 6 remain, and the code needs three digits, so the code is made of 2, 4 and 6 in some order.
  2. Attempt 2 6 3: zero in place, two misplaced. The two misplaced digits are 2 and 6, as expected. Zero in place means that 2 is not in position 1 and 6 is not in position 2.
  3. Attempt 4 2 1: one in place, one misplaced. The digits 4 and 2 are both in the code, so exactly one of them is where the attempt has it: either 4 is in position 1 or 2 is in position 2, not both.
  4. Suppose 4 is in position 1. Then 2 is the misplaced one and is not in position 2. Position 1 is taken, so 2 goes in position 3, and 6 is left with position 2. Step 2 forbids that. The supposition is false.
  5. So 2 is in position 2 and 4 is the misplaced one: it is not in position 1, and position 2 is taken, so 4 goes in position 3. The 6 takes position 1.
  6. Check. The code is 6 2 4. Against 1 3 5: nothing. Against 2 6 3: the 2 and the 6 are there but moved. Against 4 2 1: the 2 is in place and the 4 is not.

Every attempt was needed. Remove any of the three and two or more codes would fit.

Common mistakes

  • Reading "misplaced" as "wrong". A misplaced digit is in the code. It is in another position.
  • Counting a digit twice. "One in place, one misplaced" speaks about two different digits.
  • Deciding which digit an answer refers to. "One in place" does not say which. Until you can prove it, keep every option open.
  • Using only the positive answers. Zeros place nothing, but they cross out digits and ban positions, and that is what makes the other attempts readable.
  • Entering a code that fits most attempts. The code must fit all of them. The app marks the attempts that your code contradicts.

How the difficulty grows in the app

Crack the Lock has 120 levels. The tutorials and the easy levels use three positions and the digits 1 to 6, which makes 120 possible codes, with three or four attempts. In them each answer is also written out as a sentence, such as "One digit correct, but misplaced", and the first ones always include an attempt where nothing is correct.

Medium levels show the two numbers only. They alternate three positions with the digits 0 to 9 (720 codes) and four positions with the digits 1 to 6 (360 codes), with four or five attempts. Hard levels have four positions and ten digits, 5,040 possible codes, with five or six attempts and never one where nothing is correct. Steps there need two or three attempts read together, several times in a row.

A hint tells you one fact and where it comes from: that a digit is not in the code, that it is, or that only one digit can go in a position, and whether a single highlighted attempt proves it or several do together with what you have already noted. For the same kind of reasoning with people in place of digits, see Take a Seat, or browse all the games.

Frequently asked questions

How do you solve a "crack the code" puzzle with clues?

Cross out the digits of any attempt where nothing is correct, add the two numbers of each other attempt to find out which digits are in the code, and use the attempts with zero in place to ban positions. If two options remain, suppose one and look for a contradiction.

What do "in place" and "misplaced" mean?

In place: the digit is in the code and in that same position. Misplaced: the digit is in the code, but in a different position. A digit that is not in the code counts for neither.

Can a digit repeat in the code?

Not in Crack the Lock. The code and the attempts never repeat a digit, which is the classic rule of Bulls and Cows. Other code games allow repeats, and the counting changes with them.

Is there only one code that fits?

Yes. A program checks every level before it ships: exactly one code agrees with all the attempts.

More games in the collection