1
$\begingroup$

Your suitcase has 4-digit code lock. You forgot the code, but you do remember that the sum of first two digits was equal to the sum of two second digits. How many combinations do you need to check in the worst possible scenario?

What methods can be used to solve this?

$\endgroup$
1
  • $\begingroup$ Decimal digits? Hex digits? Binary digits? In any case, it's trivially easy to write a script to enumerate the options and check the condition and then count them. $\endgroup$
    – Sycorax
    Jul 15, 2016 at 15:16

3 Answers 3

4
$\begingroup$

This is a permutation problem, and it is like the sum of a dice roll problem. Consider that the sum of the first two digits is 0, then the combination is 0000. If the sum of the first two digits is 18, then the combination is 9999. Now consider if the sum of the first two digits is 1, then the possible combinations are 1001, 1010, 0110, 0101, and if the sum of the first two digits is 17, then we have 9889, 9898, 8998, 8989.

Now you should start to see a pattern. (Sum of 2 Digit Numbers = Sums, Number of 2 Digit Combinations = 2Dig, Number of 4 Digit Combinations = 4Dig)

Sums    2Dig    4Dig
0       1       1
1       2       4
2       3       9
3       4       16
4       5       25
...
9       10      100
...
14      5       25
15      4       16
16      3       9
17      2       4
18      1       1

Now you can see that the total number of 4 digit combinations should be the sum of $2Dig ^2$.

This equals 670

$\endgroup$
2
$\begingroup$

Assuming decimal digits:

The first two digits can be anything from 00 to 99. There are a total of 100 possibilities for these first two digits.

You would then need to test the remaining two digits for each of the possible first two digits. The number of times you would need to test would be equal to the number of possible sum combinations.

The sum of these two digits can range from 0 to 18.

Sum            0  1  2  3  4  5  6  7  8   9  10  11  12  13  14  15  16  17  18 
Combinations   1  2  3  4  5  6  7  8  9  10   9   8   7   6   5   4   3   2   1

For 00, the sum is 0. You would only need to test sums of 0, which there are 1. For 09, you would need to test 10 different combinations of sums of 9. For example, you would test 0909, 0918, 0927, etc. Note that the first two digits are also seen in the last two digits (09 and 09). There are a total of 10*10 = 100 different combinations where the first and last two digits have a sum of 9.

The total number of combinations should be 1*1 + 2*2 + 3*3 + ... + 9*9 + 8*8 + ... + 1*1.

This is equal to 670.

$\endgroup$
1
$\begingroup$

I can confirm the results by Kontorus with the following script:

# Define numbers
nums <- 0:9

counter <- 0
for(i in nums){
  for(j in nums){
    for(k in nums){
      for(l in nums){
        if(i+j == k+l){
          counter <- counter + 1
        }
      }
    }
  }
}
(counter)

Yields 670. You can change the range of numbers to try non-decimal, but then you need to define an addition operator for them, but I assume that addition is meant as addition for base 10.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.