You've probably seen the picture. A padlock with three dials, and five lines of clues under it: 682, one number is correct and well placed. 614, one number is correct but wrong placed. And somewhere in the comments, someone insists the answer is obviously 042.
They're right, as it happens. But the useful part is how you get there, because the same method solves every puzzle of this kind. Lock riddles, code breaker puzzles, bulls and cows, even Mastermind with digits instead of colored pegs: they all run on the same two numbers per clue.
I build these puzzles for my game Crack the Vault, and a step by step solver checks that every one can be cracked with logic alone. The examples below come straight out of that solver, so every step is one you can follow with a pencil.
The rules in one minute
A secret code has 3, 4 or 5 digits. In my puzzles, and in most lock riddles, no digit appears twice, and a code may start with 0. Each clue shows a guess and two counts:
- how many digits of the guess are in the code at all,
- and how many of those sit in exactly the right slot.
Bulls and cows calls the second count bulls and the rest cows. Lock riddles spell it out: "two numbers are correct but wrong placed". My daily vault says it in full, like "Exactly 2 digits are correct in total, of which 1 is in the correct position."
It helps to know how big the haystack is. With different digits there are 720 possible 3 digit codes, 5,040 with 4 digits and 30,240 with 5. A good clue throws most of them away at once. In the 682 riddle, the first clue alone leaves 126 of the 720. The second cuts that to 30, and after the third there's just one code left.
The idea that does most of the work
Pick one clue and one digit of its guess. That digit lands in exactly one of three boxes:
- In place: it's in the code, in the slot where the guess has it.
- Misplaced: it's in the code, in some other slot.
- Absent: it's not in the code at all.
The clue tells you exactly how many of the guess's digits go in each box. Take "Exactly 2 digits are correct in total, of which 1 is in the correct position" on a 4 digit guess. That's one digit in place, one misplaced and two absent.
Most people remember the first two numbers and forget the third. But the absent count is often the strongest fact on the page, because any digit the clue doesn't count simply isn't in the code.
Once you think in boxes, almost every deduction comes down to one question. Is this box already full, or are there only just enough digits left to fill it?
Seven moves that crack almost any code
My solver knows exactly these seven moves, and it always tries the simplest one first. That's a good order for people too.
- Cross out a none clue. "None of these digits is in the code" removes every digit of that guess from every slot. Do this first.
- Spot a box that's already full. Say a clue needs one digit in place and you already know which one it is. Then every other digit of that guess is not in its shown slot. And when a clue's absent box is full, its remaining digits must be in the code.
- Spot a box that can only just be filled. If a clue needs two absent digits and only two of its digits can still be absent, both are out. Same idea when it needs one digit in place and only one can still be there: that digit goes in that slot.
- Fill the last digit of a slot. When every other digit is ruled out of a slot, the one that's left goes there.
- Use the last free slot. A digit you know is in the code, with one free slot left, goes in it. And a digit with no free slot at all isn't in the code.
- Count the digits. Once you know all 4 digits of a 4 digit code, every other digit is out. Turn it around too: when exactly 4 candidates are left for a 4 digit code, they're all in.
- Ask what if. Suppose a digit is in the code (or in a slot) and follow moves 1 to 6. If some clue breaks, the opposite must be true. It's the last resort, and good puzzles rarely need it.
For keeping track, nothing beats a small grid. One row per digit from 0 to 9, one column per slot. Cross out cells as you rule them out, and circle a digit once you know it's in the code. The notes row in my daily code breaker is a one line version of the same thing.
Example 1: the 682 lock riddle
This is the one that keeps going around social media. In my wording, the five clues read like this:
| Clue | Guess | What it tells you |
|---|---|---|
| 1 | 682 | Exactly 1 digit is correct and in the correct position. |
| 2 | 614 | Exactly 1 digit is in the code but in a different position. |
| 3 | 206 | Exactly 2 digits are in the code but in different positions. |
| 4 | 738 | None of these digits is in the code. |
| 5 | 780 | Exactly 1 digit is in the code but in a different position. |
How a person solves it. 738 has nothing correct, so 7, 3 and 8 are out. Then 780 says one of 7, 8 and 0 is in the code but in the wrong place. With 7 and 8 gone, 0 must be in the code, and not in slot 3.
Now 682. One digit is right and in place, and 8 is already out. Could it be 6, in slot 1? Look at 614, which also has 6 in slot 1. Its correct digit has to be misplaced, so 6 can't sit in slot 1 there. That rules out 6 and leaves 2, which goes in slot 3.
The clue 206 says two digits are in the code, both in the wrong place. With 6 out, those are 2 and 0, and 0 isn't in slot 2. Slot 3 already belongs to 2, so 0 takes slot 1.
Last, 614 needs one more correct digit, misplaced. It isn't 6. Could it be 1? It would have to avoid slot 2, but slot 2 is the only one left. So it's 4, in slot 2, and the code is 042.
I checked one more thing. Even if codes could repeat digits, 042 is still the only one of all 1,000 codes from 000 to 999 that fits every clue. Here's the solver's own route:
| Step | Why | So |
|---|---|---|
| 1 | Clue 4 says none of its digits is in the codeMove 1: none clue | 7, 3 and 8 aren't in the code |
| 2 | Clue 1 has no correct digit in a different slotMove 2: box already full | 2 isn't in slots 1 or 2; 6 isn't in slots 2 or 3 |
| 3 | Clue 2 has no digit in the right slotMove 2: box already full | 1 isn't in slot 2; 4 isn't in slot 3; 6 isn't in slot 1 |
| 4 | 6 has no slot left where it could goMove 5: no slot left | 6 isn't in the code |
| 5 | Clue 1 needs 1 digit in the right slot, and only 2 can still be thereMove 3: box only just fits | 2 goes in slot 3 |
| 6 | Clue 3 has no digit in the right slotMove 2: box already full | 0 isn't in slot 2 |
| 7 | Clue 3 has 1 digit that isn't in the code, and 6 is already that oneMove 2: box already full | 0 is in the code |
| 8 | Suppose 1 is in the code, then slot 1 would have no digit leftMove 7: what if | 1 isn't in the code |
| 9 | Clue 2 has 2 digits that aren't in the code, and 6 and 1 are already thoseMove 2: box already full | 4 is in the code |
| 10 | The code has 3 digits, and you already know 0, 2 and 4 are in itMove 6: all digits found | 5 and 9 aren't in the code |
| 11 | Only 4 can still go in slot 2Move 4: last digit for a slot | 4 goes in slot 2 |
Step 8 is worth a look. The solver supposes 1 is in the code and finds that slot 1 would have no digit left. A person says it the way I did above: "if it were 1, there'd be nowhere to put it." Same idea, different words.
Example 2: a 4 digit vault
This one comes from the generator behind my medium vaults. Give it a try before you read on.
| Clue | Guess | What it tells you |
|---|---|---|
| 1 | 6847 | None of these digits is in the code. |
| 2 | 9305 | Exactly 3 digits are correct in total, of which 1 is in the correct position. |
| 3 | 0524 | Exactly 2 digits are in the code but in different positions. |
| 4 | 6583 | Exactly 2 digits are in the code but in different positions. |
| 5 | 9456 | Exactly 1 digit is correct and in the correct position. |
How a person solves it. Clue 1 removes 6, 8, 4 and 7. Clue 4 (6583) has two digits in the code, both misplaced. Two of its digits, 6 and 8, are out, so the other two must be in: 5 and 3. Neither sits where clue 4 shows it, so 5 isn't in slot 2 and 3 isn't in slot 4.
Clue 5 (9456) has exactly one digit in the code, in place. 4 and 6 are out and 5 is in, so 5 is that digit. It goes in slot 3, and 9 is out.
Clue 2 (9305) has three digits in the code. With 9 out, those are 3, 0 and 5, and exactly one of them is in place. It isn't 5 (that's in slot 3, not slot 4), and it can't be 0 either, since slot 3 is taken. So 3 is in place, in slot 2.
Clue 3 (0524) has two digits in the code, 0 and 5, which knocks out 2. That leaves only one digit nobody has ruled out: 1. So the code is made of 3, 5, 0 and 1. Clue 3 also keeps 0 out of slot 1, so 0 takes slot 4 and 1 takes slot 1. The answer is 1350.
| Step | Why | So |
|---|---|---|
| 1 | Clue 1 says none of its digits is in the codeMove 1: none clue | 6, 8, 4 and 7 aren't in the code |
| 2 | Clue 3 has no digit in the right slotMove 2: box already full | 0 isn't in slot 1; 2 isn't in slot 3; 5 isn't in slot 2 |
| 3 | Clue 4 has no digit in the right slotMove 2: box already full | 3 isn't in slot 4 |
| 4 | Clue 4 has 2 digits that aren't in the code, and 6 and 8 are already thoseMove 2: box already full | 5 and 3 are in the code |
| 5 | Clue 5 has 3 digits that aren't in the code, and only 9, 4 and 6 can still be missingMove 3: box only just fits | 9 isn't in the code |
| 6 | Clue 2 has 1 digit that isn't in the code, and 9 is already that oneMove 2: box already full | 0 is in the code |
| 7 | Clue 3 has 2 digits that aren't in the code, and only 2 and 4 can still be missingMove 3: box only just fits | 2 isn't in the code |
| 8 | Clue 5 needs 1 digit in the right slot, and only 5 can still be thereMove 3: box only just fits | 5 goes in slot 3 |
| 9 | Clue 2 needs 1 digit in the right slot, and only 3 can still be thereMove 3: box only just fits | 3 goes in slot 2 |
| 10 | Only 1 can still go in slot 1Move 4: last digit for a slot | 1 goes in slot 1 |
Example 3: a vault that needs one what if
Harder vaults sometimes need move 7. In this one, the straightforward moves dry up after a few steps.
| Clue | Guess | What it tells you |
|---|---|---|
| 1 | 3561 | Exactly 2 digits are correct in total, of which 1 is in the correct position. |
| 2 | 6572 | Exactly 3 digits are correct and in the correct positions. |
| 3 | 1073 | Exactly 2 digits are correct in total, of which 1 is in the correct position. |
| 4 | 3126 | Exactly 1 digit is in the code but in a different position. |
| 5 | 8613 | Exactly 1 digit is in the code but in a different position. |
| 6 | 5638 | Exactly 2 digits are in the code but in different positions. |
Clue 2 is the strongest line here. Three of 6, 5, 7 and 2 sit exactly where the guess shows them, and the fourth isn't in the code at all. After the first easy eliminations nothing else follows directly, so the solver asks a what if question: suppose 1 is in the code.
Clue 4 (3126) has exactly one digit in the code. If that digit is 1, then 3, 2 and 6 are all out. But clue 2 needs three of 6, 5, 7 and 2, and with 6 and 2 gone only two are left. That breaks clue 2.
So 1 isn't in the code, and from there the simple moves finish the job. The code is 6570.
| Step | Why | So |
|---|---|---|
| 1 | Clue 2 has no correct digit in a different slotMove 2: box already full | 2 isn't in slots 1, 2 or 3; 5 isn't in slots 1, 3 or 4; 6 isn't in slots 2, 3 or 4; 7 isn't in slots 1, 2 or 4 |
| 2 | Clue 4 has no digit in the right slotMove 2: box already full | 1 isn't in slot 2; 3 isn't in slot 1 |
| 3 | Clue 5 has no digit in the right slotMove 2: box already full | 1 isn't in slot 3; 3 isn't in slot 4; 8 isn't in slot 1 |
| 4 | Clue 6 has no digit in the right slotMove 2: box already full | 3 isn't in slot 3; 8 isn't in slot 4 |
| 5 | Suppose 1 is in the code, then clue 2 can't be true anymoreMove 7: what if | 1 isn't in the code |
| 6 | Clue 1 needs 1 digit in the right slot, and only 5 can still be thereMove 3: box only just fits | 5 goes in slot 2 |
| 7 | 3 has no slot left where it could goMove 5: no slot left | 3 isn't in the code |
| 8 | Clue 1 has 2 digits that aren't in the code, and 3 and 1 are already thoseMove 2: box already full | 6 is in the code |
| 9 | Clue 3 needs 1 digit in the right slot, and only 7 can still be thereMove 3: box only just fits | 7 goes in slot 3 |
| 10 | 8 has no slot left where it could goMove 5: no slot left | 8 isn't in the code |
| 11 | Clue 2 has 3 digits in the right slot, and 6, 5 and 7 are already thoseMove 2: box already full | 2 isn't in slot 4 |
| 12 | 2 has no slot left where it could goMove 5: no slot left | 2 isn't in the code |
| 13 | Clue 3 has 2 digits that aren't in the code, and 1 and 3 are already thoseMove 2: box already full | 0 is in the code |
| 14 | The code has 4 digits, and you already know 0, 5, 6 and 7 are in itMove 6: all digits found | 4 and 9 aren't in the code |
| 15 | Only 0 can still go in slot 4Move 4: last digit for a slot | 0 goes in slot 4 |
When you're stuck, here's a habit that works well. Pick the digit that shows up in the most clues and ask what happens if it's in the code. Clues that share a lot of digits break quickly, and that's exactly what you want.
When you make the guesses yourself
In bulls and cows and Mastermind style games, nobody hands you the clues. You choose each guess and get the two counts back. The seven moves still decide what you know. What changes is how you pick the next guess.
Your first guess doesn't matter. It sounds wrong, but it follows from symmetry. When codes use different digits, every first guess splits the possible codes in exactly the same way, because swapping digit names or slot order turns one guess into any other. Here's what the answer to the guess 0123 tells you about a 4 digit code:
| Answer to the guess 0123 | Codes | Share |
|---|---|---|
| 1 in the code, 0 of them in the right place | 1,440 | 28.6% |
| 2 in the code, 0 of them in the right place | 1,260 | 25.0% |
| 2 in the code, 1 of them in the right place | 720 | 14.3% |
| 1 in the code, 1 of them in the right place | 480 | 9.5% |
| None of the digits is in the code | 360 | 7.1% |
| 3 in the code, 0 of them in the right place | 264 | 5.2% |
| 3 in the code, 1 of them in the right place | 216 | 4.3% |
| 2 in the code, 2 of them in the right place | 180 | 3.6% |
| 3 in the code, 2 of them in the right place | 72 | 1.4% |
| 3 in the code, 3 of them in the right place | 24 | 0.5% |
| 4 in the code, 0 of them in the right place | 9 | 0.2% |
| 4 in the code, 1 of them in the right place | 8 | 0.2% |
| 4 in the code, 2 of them in the right place | 6 | 0.1% |
| All digits correct: you have cracked it | 1 | 0.0% |
The most likely answer is one digit right but misplaced, which still leaves 1,440 codes. "Nothing right" sounds bad, but it's much better news: only 360 codes remain, and four digits are gone for good.
Make guesses that could be right. A simple strategy that works well is to always guess a code that fits every answer so far. It keeps you honest, and any guess can win. Want to squeeze out the last guess? Prefer one that splits the remaining codes into many small groups, even if it can't be the answer itself.
Change a little at a time. Keep one or two digits you're unsure about from the last guess, swap the rest, and move a known digit to a new slot. Change everything at once and the answers get hard to compare.
Check your own puzzle
Found a lock riddle somewhere, or stuck in a game? Type the guesses and their counts below. The checker lists every code that still fits, and once only one is left, it shows the steps to get there. It assumes codes with different digits, like my vaults and most riddles.
Common mistakes
- Forgetting the absent digits. "One number is correct" also says the other numbers of that guess are wrong. That's usually the more useful half of the clue.
- Putting a misplaced digit back in the same slot. A misplaced digit is in the code, but never in the slot where that guess shows it.
- Reading one clue at a time. Most steps come from two clues together: one tells you a digit is in the code, the other tells you that clue's box is now full.
- Guessing early. In a puzzle with given clues, there's exactly one code that fits. If two still seem to fit, you've missed something. Check every line against your answer before you commit.
Practice
Three fresh vaults are waiting in the daily code breaker: 3, 4 and 5 digits, each with exactly one answer. Its hint button explains the next step in the same words as this guide. And if you want 500 more of these, that's what Crack the Vault is. It climbs from 3 to 5 digit codes, has its own daily vault, and it works offline.
Crack the Vault
500 levels, a daily vault and an endless mode. It works offline and you don't need an account.