Yes, that's a coincidence!

Logic Level 3

Ashish was admiring the output of his new program to generate random number. He had printed out the first ten numbers of the results. He soon noticed that each of the ten numbers had exactly one digit, in the proper placement, of the 5 digit code he used to open his car door without a key. Find Ashish's car entry code from these first 10 randomly generated numbers : 14073 , 79588 , 05892 , 84771 , 63136 , 42936 , 37145 , 50811 , 98174 , a n d 29402 14073,\space 79588, \space 05892, \space 84771, \space 63136,\space 42936, \space 37145,\space 50811,\space 98174,\space and \space 29402 . Ashish has announced that he will give his car to that person who will crack the key number.

Explicit Example: if Ashish's key code is 12345(obviously not the solution), then a randomly generated number will be such that, one and only one of its digit will match with the car key. Suppose the number generated is 54321. Now this number has 3 which matches with the car keys. Another number say 12543, has 2 as the matching digit.

Second Explicit Example: In the fist number 14073, Ashish's car code could not be 34170(two digits correctly placed(4 and 7)) or 92365 (none).


The answer is 39876.

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

Hung Woei Neoh
Jun 21, 2016

@Ashish Siva when can I pick up my car?

Now, imagine if the code is 12345 12345 , and the 10 10 generated numbers are like this:

19999 , 19999 , 9 2999 , 9 2999 , 99 399 , 99 399 , 999 49 , 999 49 , 9999 5 , 9999 5 \color{#D61F06}{1}9999,\;\color{#D61F06}{1}9999,\;9\color{#D61F06}{2}999,\;9\color{#D61F06}{2}999,\;99\color{#D61F06}{3}99,\;99\color{#D61F06}{3}99,\;999\color{#D61F06}{4}9,\;999\color{#D61F06}{4}9,\;9999\color{#D61F06}{5},\;9999\color{#D61F06}{5}

We can see that each digit of the actual code should appear on 2 2 generated numbers on average

Now, notice that for the 10 10 generated codes:

14073 , 79588 , 05892 , 84771 , 63136 , 42936 , 37145 , 50811 , 98174 , 29402 \color{#D61F06}{1}4073,\;\color{#D61F06}{7}9588,\;\color{#D61F06}{0}5892,\;\color{#D61F06}{8}4771,\;\color{#D61F06}{6}3136,\;\color{#D61F06}{4}2936,\;\color{#D61F06}{3}7145,\;\color{#D61F06}{5}0811,\;\color{#D61F06}{9}8174,\;\color{#D61F06}{2}9402

The first digit of the codes are all different, which implies that only 1 1 number has the correct first digit. This in turn implies that one of the digits in the correct position appears on 3 3 distinct generated numbers. We check for this, and find two possible cases:

140 73 , 79588 , 05892 , 847 71 , 63 136 , 42936 , 37 145 , 50811 , 98 1 74 , 29402 140\color{#EC7300}{7}3,\;79588,\;05892,\;847\color{#EC7300}{7}1,\;63\color{#20A900}{1}36,\;42936,\;37\color{#20A900}{1}45,\;50811,\;98\color{#20A900}{1}\color{#EC7300}{7}4,\;29402

Either the 3 rd 3^{\text{rd}} number is 1 \color{#20A900}{1} , or the 4 th 4^{\text{th}} number is 7 \color{#EC7300}{7} . No other method, we gotta do a case by case analysis


Case 1: 3 rd 3^{\text{rd}} number is 1 \color{#20A900}{1}

Now, we know that the 4 th 4^{\text{th}} number cannot be 7 \color{#EC7300}{7} . This implies that the remaining correct digits each appear in 2 2 distinct numbers. We check the 5 th 5^{\text{th}} digit for such a number:

14073 , 79588 , 0589 2 , 8477 1 , 63136 , 42936 , 37145 , 5081 1 , 98174 , 2940 2 14073,\;79588,\;0589\color{#3D99F6}{2},\;8477\color{#69047E}{1},\;\color{#20A900}{63136},\;42936,\;\color{#20A900}{37145},\;5081\color{#69047E}{1},\;\color{#20A900}{98174},\;2940\color{#3D99F6}{2}

We have two possibilities: 1 \color{#69047E}{1} or 2 \color{#3D99F6}{2}

Suppose that the 5 th 5^{\text{th}} digit is 1 \color{#69047E}{1} :

14 073 , 79 588 , 05 892 , 84771 , 63136 , 42 936 , 37145 , 50811 , 98174 , 29 402 14\color{#27D2E7}{0}73,\;79\color{#27D2E7}{5}88,\;05\color{#27D2E7}{8}92,\;\color{#69047E}{84771},\;\color{#20A900}{63136},\;42\color{#27D2E7}{9}36,\;\color{#20A900}{37145},\;\color{#69047E}{50811},\;\color{#20A900}{98174},\;29\color{#27D2E7}{4}02

The remaining 3 rd 3^{\text{rd}} digits are all distinct, therefore this combination is not possible

Instead, we try 2 \color{#3D99F6}{2} as the 5 th 5^{\text{th}} digit:

14 073 , 79 588 , 05892 , 84 771 , 63136 , 42 936 , 37145 , 50 811 , 98174 , 29402 14\color{#27D2E7}{0}73,\;79\color{#27D2E7}{5}88,\;\color{#3D99F6}{05892},\;84\color{#27D2E7}{7}71,\;\color{#20A900}{63136},\;42\color{#27D2E7}{9}36,\;\color{#20A900}{37145},\;50\color{#27D2E7}{8}11,\;\color{#20A900}{98174},\;\color{#3D99F6}{29402}

Similarly, the remaining 3 rd 3^{\text{rd}} digits are all distinct, therefore this combination is not possible too.

We can conclude that Case 1 is not possible, and the correct answer lies in Case 2


Case 2: 4 th 4^{\text{th}} number is 7 \color{#EC7300}{7}

The 3 rd 3^{\text{rd}} number cannot be 1 \color{#20A900}{1} , and the remaining digits appear in two numbers each. We repeat the same steps earlier:

14073 , 79588 , 0589 2 , 84771 , 6313 6 , 4293 6 , 37145 , 50811 , 98174 , 2940 2 \color{#EC7300}{14073},\;79588,\;0589\color{#E81990}{2},\;\color{#EC7300}{84771},\;6313\color{#BBBBBB}{6},\;4293\color{#BBBBBB}{6},\;37145,\;50811,\;\color{#EC7300}{98174},\;2940\color{#E81990}{2}

It can be 2 \color{#E81990}{2} or 6 \color{#BBBBBB}{6} .

We test the number 2 \color{#E81990}{2} first:

14073 , 7 9588 , 05892 , 84771 , 6 3136 , 4 2936 , 3 7145 , 5 0811 , 98174 , 29402 \color{#EC7300}{14073},\;7\color{#27D2E7}{9}588,\;\color{#E81990}{05892},\;\color{#EC7300}{84771},\;6\color{#27D2E7}{3}136,\;4\color{#27D2E7}{2}936,\;3\color{#27D2E7}{7}145,\;5\color{#27D2E7}{0}811,\;\color{#EC7300}{98174},\;\color{#E81990}{29402}

The remaining 2 nd 2^{\text{nd}} digits are all distinct, therefore this combination is not possible

Therefore, we know that the 5 th 5^{\text{th}} digit must be 6 \color{#BBBBBB}{6}

14073 , 7 9588 , 05 892 , 84771 , 63136 , 42936 , 37145 , 50 811 , 98174 , 2 9402 \color{#EC7300}{14073},\;7\color{teal}{9}588,\;05\color{magenta}{8}92,\;\color{#EC7300}{84771},\;\color{#BBBBBB}{63136},\;\color{#BBBBBB}{42936},\;\color{#D61F06}{3}7145,\;50\color{magenta}{8}11,\;\color{#EC7300}{98174},\;2\color{teal}{9}402

From here, we can decude the remaining digits. The 2 nd 2^{\text{nd}} digit must be 9 \color{teal}{9} , and the 3 rd 3^{\text{rd}} digit must be 8 \color{magenta}{8} . This leaves us with 3 \color{#D61F06}{3} as the 1 st 1^{\text{st}} digit


140 73 , 7 9588 , 05 892 , 847 71 , 6313 6 , 4293 6 , 37145 , 50 811 , 981 74 , 2 9402 140\color{#EC7300}{7}3,\;7\color{teal}{9}588,\;05\color{magenta}{8}92,\;847\color{#EC7300}{7}1,\;6313\color{#BBBBBB}{6},\;4293\color{#BBBBBB}{6},\;\color{#D61F06}{3}7145,\;50\color{magenta}{8}11,\;981\color{#EC7300}{7}4,\;2\color{teal}{9}402

Ashish's car entry code is 3 9 8 7 6 \large\boxed{\color{#D61F06}{3}\color{teal}{9}\color{magenta}{8}\color{#EC7300}{7}\color{#BBBBBB}{6}}

Kk come to my house tmrw.

Ashish Menon - 4 years, 11 months ago

I was the first one, So I get the Porche XD

Abhay Tiwari - 4 years, 11 months ago

That's a way of solving it. For clarity you can also add a table with all the repeating digits based on their positions in the code anyway.

A A - 4 years, 11 months ago

This problem can be easily solved using a brute-force search through all possible 5-digit codes and comparing them with the given generated numbers. This isn't a solution that uses extensive application of logic, but I think it is a valid solution nonetheless.

from itertools import permutations

givens = ["14073", "79588", "05892", "84771", "63136", "42936", "37145", "50811", "98174", "29402"]
for p in permutations([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], r = 5):
    s = ""
    for c in p: s += str(c)
    counts = 0
    for g in givens:
        digits_in_common = 0
        for i in range(5):
            if s[i] == g[i]: digits_in_common += 1
        if digits_in_common == 1: counts += 1
    if counts == len(givens):
        print(s)
        break

The program above outputs 39876 \boxed{39876} .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...