Math puzzle

Here’s a real-life math puzzle I encountered:

I bought a Key Safe like the one pictured here for my cabin.
I can now let friends use the cabin by just telling them the combination I’ve set this week.
Key safe

When I bought it I didn’t know how many combinations were available. (My old dial lock box with 20 positions seemed to have 20 x 20 x 20 = 8000 combinations.)

It turns out the combination can be 1 to 10 digits long. That would seem to imply that there are 10[sup]10 [/sup]combinations.

But then it said the order the digits were pressed was immaterial - that a combination of 2-5-8 could be opened with a press of 5-8-2 or 5-5-2-8-8 etc.

So there are 10 single-digit combinations.
And 45 two-digit combinations (That’s computed by 10 x 10 =100. Less the 10 with duplicates = 90. And divide by 2 because order doesn’t matter =45)
Then for 3-digit combinations…

It seemed like going on like that, up to 10-digit combinations, would take a lot of calculation.

But I found an easy formula. Can you spot it?


Poster at Fathom

n!
n_C_k = ----------
k!(n - k)!

n=10
k=number of positions


            n!
     n_C_k = ----------
                   k!(n - k)!


Lemme try that again.

It’s a pretty standard homework problem. What’s the formula you found?

Here’s a more interesting question: what’s the shortest sequence you’d need to key in to try all the combinations? If order mattered, you’d use the de Bruijn sequence, but that would have a lot of duplicates in this scenario.

You know, I totally missed that the code length can range from 1 to 10. In that case, there are 1023 possible combinations (cause that’s 2[sup]10[/sup] - 1).

UncleRojelio Sorry. I tried both your formulae and the result was not the right answer.
ultrafilter Close, but not correct.
Also, I’m pretty sure the shortest sequence is simply to try all 1-button-down sequences, followed by 2-button, etc. Hard to beat that, that I can see.


Poster at Fathom

ultrafilter - My mistake. Actually, your answer of 1023 is correct as the problem was given. I was confused because the real answer is 1024, but then the real key safe allows the code with no buttons pressed, for a code length from 0 to 10.

Let’s see…no duplicates allowed, order doesn’t matter, and it’s a 1-10 digit sequence on the digits 0-9, right? Mine is the right answer to that problem. Check your work.

If order matters, that’s significantly longer than the shortest sequence. I’ll get an actual figure for you later.

Order doesn’t matter, as stated above. So from a random point of view, all combinations are equally likely (unlike a dial lock, and unlike dice, etc.)
So the only factor for speed is how quickly a human can press the digits, so you’d try the fewest digit first. (This is NOT the order of lowest binary numbers, which have mixed numbers of actual button presses.)
Thus the best order is
0000000000
1000000000
0100000000
0010000000
:


[http://fff.fathom.org/forums/member.php?action=getinfo&userid=2111

Of course, you might consider human preferences for pass codes.
Many people would try a birthday or year or some such, and eschew the simpler 1-digit combinations as too easy. And I’d guess few people will go for all buttons pressed, as also too simple.

But psychology and math are not very close froends :wink:


Poster at Fathom

I’m still not 100% clear on exactly how this thing works–whether it’s a key-pad and the right combination of digits gets you in, or if it’s a bunch of on-off switches and having the right switches on gets you in. Either way, there’s a faster way to try all the combinations than the naive way.

Imagine a keypad with three keys that’s unlocked by a code of length two, independent of order. The only possibilities are 01, 02, and 12. The naive approach is to key 010212, but keying 0120 works as well (since 20 is the same 02).

Imagine a set of three switches. The naive approach has you try all the combinations in the order (000, 001, 010, 011, 100, 101, 110, 111), which is a total of 11 switch flips. Trying (000, 001, 011, 010, 110, 100, 101, 111) will get you in with only eight switch flips.

No switches.
You press the little round buttons.
And when the correct button have all been pressed the square latch is free to slide down and the door drops open.

Once a little round button is pressed, it stays down until either the safe is opened or you slide down the Clear button at the center of the picture.

But, you are right. For a length of two, the combinations possible are neither, the “1” button down, the “2” button down, and finally both “1” and “2” down.

You have to test after each potential combination, but
my naive way was:
Clear, try to open
Clear,1, try to open
Clear,2, try to open
Clear,1,2, try to open
[= 12 actions to try all combinations]

Your optimized method ( reminds me of the premise behind Gray Code )

Clear, try to open
1, try to open
(1 is still down) 2, try to open
Clear, 2, try to open
[= 9 actions to try all combinations]

Surely by the time you got to 10 digit the effect would be very considerable.
So, my hat’s off to you, well done!

Heh.

That’s the concept I had in mind, but I couldn’t for the life of me remember the name of it. Now I have to go see if there’s such a thing as a Spalding graph, or if my brain was subconsciously riffing of Spalding Gray.

Yep, except you need a modified Gray Code because the 0->1 flip can be done but the 1->0 flip requires all the buttons to go back to reset.

I’ll have to think about that a bit.