Breaking the Code

Logic Level 3

The door is locked with a 10-digit code, consisting of 10 distinct digits in the combination. The only way to get in is to press all the numbers correctly.

When you try 1234567890 1234567890 , the computer tells you that "only 4 numbers are in the right places."

When you try 5402361987 5402361987 , the computer still says that "only 4 numbers are in the right places."

Finally, when you try 0279314658 0279314658 , this time the computer says that "only 5 numbers are in the right places."

What is the right combination to this door lock?


The answer is 1209364857.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Compare each sequence:

1 2 3 4 5 6 7 8 9 0 => 4 corrects

5 4 0 2 3 6 1 9 8 7 => 4 corrects

x x x x x 6 x x x x


1 2 3 4 5 6 7 8 9 0 => 4 corrects

0 2 7 9 3 1 4 6 5 8 => 5 corrects

x 2 x x x x x x x x


5 4 0 2 3 6 1 9 8 7 => 4 corrects

0 2 7 9 3 1 4 6 5 8 => 5 corrects

x x x x 3 x x x x x


Consider that: 4 corrects + 4 corrects + 5 corrects = 13 corrects.

But the maximum number of correct digit must not exceed 10.

So, the 3 repeating digits (i.e. 6, 2, and 3) are the correct digits.

We can conclude that:

(i) The correct sequence must be like: x 2 x x 3 6 x x x x.

(ii) Because 13 corrects - 3 repeating corrects = exactly 10 corrects, the correct digit in each position must come from the digit from the three given sequences, e.g. the last digit is possible only for 0, 7, or 8.

After that, it seems only trial and error method manages to get this task done.

PS. I still wonder how to prove that there is only one possible solution, except using the brute force method.

I wonder that, too, 'cause I proved it by all possible trial & error. Lol...

Worranat Pakornrat - 5 years, 6 months ago

Log in to reply

Here's Python code that validates it as the unique solution. (Please excuse the sloppy coding.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import itertools
#create a list of all 10! permutations 
x = list(itertools.permutations('0123456789',10))

#this function counts how many digits are the same between two combinations
def correct(a,b):
    count = 0
    for i in range(10):
        if a[i] == b[i]: count += 1
    return count

#over all permutations, we check which have 4,4,5 the same with the given codes
for y in x:
    if correct(y,'1234567890') == 4:
        if correct(y,'5402361987') == 4:
            if correct(y,'0279314658') == 5:
                print y

Eli Ross Staff - 5 years, 6 months ago

Log in to reply

Ah, thank you for sharing. I'm not much of a computer expert.

Worranat Pakornrat - 5 years, 6 months ago

Log in to reply

@Worranat Pakornrat No problem!

I've added some comments to the code for anyone wanting to read along.

Eli Ross Staff - 5 years, 6 months ago

Report: 1209364857 is indeed the only possible answer confirmed to be true.

Lu Chee Ket - 5 years, 6 months ago

1279364980 this is also correct one.you should check out this.

Sarvesh Bodakhe - 5 years, 6 months ago

Log in to reply

Um, there's no 5 in your combination (9 occurs twice). Please check your answer again.

Worranat Pakornrat - 5 years, 6 months ago

Log in to reply

@Worranat Pakornrat Sorry to desturb you.

Sarvesh Bodakhe - 5 years, 6 months ago

What if the numbers common in both sequences (eg. 2, 3 and 6) are in wrong position?

Srinath Potnuru - 5 years, 6 months ago

Log in to reply

Well, that's a good question. Let me try explaining.

Suppose you have 3 sequences , each has 10 digits. Each sequence has the number of right digits as 4, 4, and 5. Those are:

R, R, R, R, X, X, X, X, X, X => 4 corrects.

X, X, X, R, R, R, R, X, X, X => 4 corrects.

R, X, X, X, X, X, R, R, R, R => 5 corrects

You can see that if we pair each sequence and then find that there is only one common digit in each sequence pair, those common digits must be the right digits.

Total corrects: 4 + 4 + 5 = 13

Minimum commons: 13 - 10 = 3

Total commons (1,2) + (1,3) + (2,3): 1 + 1 + 1 = 3

Therefore, all of the common digits must be the right digits.


Compare to these sequences:

R, R, R, R, X, X, X, X, X, K => 4 corrects.

R, R, X, X, R, R, X, X, X, K => 4 corrects.

R, R, X, X, X, X, R, R, R, K => 5 corrects

If we pair each sequence and then find a lot of common digits, we can't assure that the common digits are the right digits (in this case, K - the last digit - is the wrong digit). Lucky for us that this did not happen in this problem.

Total corrects: 4 + 4 + 5 = 13

Minimum commons: 13 - 10 = 3

Total commons (1,2) + (1,3) + (2,3): 3 + 3 + 3 = 9

Therefore, all of the common digits are not necessarily the right digits (the K contributed 3 commons in this example).

Hope this may help you.

Worapong Itthithaneth - 5 years, 6 months ago

Question I have is about your point (ii) above - Why should the only possible last digit be 0,7 or 8.. and not say 1,4,5, or 9??

Ajit Deshpande - 5 years, 6 months ago

1279364980 this is also the correct one.you should check this out.

Sarvesh Bodakhe - 5 years, 6 months ago
Jeriel Villa
Dec 5, 2015

I arrange them into 3 rows to see the same numbers in column clearly.

1 2 3 4 5 6 7 8 9 0

5 4 0 2 3 6 1 9 8 7

0 2 7 9 3 1 4 6 5 8

as you can see there are 2 same numbers in column 2, 5 and 6 (numbers 2,3 & 6). Then I cancel the remaining 2,3,6 and the number in between the same number

1 2 - 4 - 6 7 8 9 0 (2 left correct)

5 - 0 - 3 6 1 9 8 7 (2 left correct)

0 2 7 9 3 - 4 - 5 8 (3 left correct)

1 2 0 9 3 6 4 8 5 7 (Answer)

by that left numbers it becomes easy to solve. By trial and error I solved this

Me too it took time . I was supposed to study chemistry . how old are you . I am 17

Mohamed X Faslah - 5 years, 6 months ago

Log in to reply

its like sudoku. im 18

Jeriel Villa - 5 years, 6 months ago

Confused 😵

kealohfive Dias Stebanäk - 4 months, 1 week ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...