Key/Lock Puzzle
Phil Pilgrim (PhiPi)
Posts: 23,514
I'm working on a mechanical puzzle that requires 256 "keys" and 256 "locks." Each key must fit one and only one lock. Unlike a traditional tumbler, though, if a key can be pushed into the lock, it's deemed to fit. The keys are coded in binary, as shown below:
As is obvious from the far-right image, not all binary combinations of keys and locks are suitable, since we don't want a wrong key to "fit." So the puzzle is this: how many bit positions, and what binary encoding, will be required as a minimum to accommodate 256 keys and 256 locks? I think I know the answer, but let's see what the forum comes up with.
-Phil
P.S. If you suggest Manchester (or similar) encoding, each "bit" will count as two bits. Also, the bit widths for 1 and 0 must be the same.
As is obvious from the far-right image, not all binary combinations of keys and locks are suitable, since we don't want a wrong key to "fit." So the puzzle is this: how many bit positions, and what binary encoding, will be required as a minimum to accommodate 256 keys and 256 locks? I think I know the answer, but let's see what the forum comes up with.
-Phil
P.S. If you suggest Manchester (or similar) encoding, each "bit" will count as two bits. Also, the bit widths for 1 and 0 must be the same.
Comments
Edit: As I think about this a bit more, I'm betting the answer ends up being less than 16. This calls for someone good at permutations and combinations. It's been awhile since I've done that sort of math.
-Phil
BTW, if you have enough bits to get 256 locks, you could have 495 locks.
I get 462 instead of 495. Had I relaxed my requirements to 252, one fewer bit position would've sufficed.
The question then becomes, "Working with fewer bit positions, can you replace some of the "n ones" combinations with larger numbers of "n-1 ones" combinations to buy more total combinations?"
-Phil
You're right (according to my latest attempt). I get 462 two different ways (same number of total bits). The number of ones and zeros is of course reversible. It doesn't require 8 ones as I had originally assumed.
You allude to a mathematical solution, I just took the brute force approach and tested bits.
As a result of this exercise, I think my puzzle will have 252 pieces, rather than 256.
But, come to think of it, a straight binary coding may be even more diabolical. I believe that, if one key "fits" a lock incorrectly, that means that when all the other keys are fittted correctly, there will still be one pair left over that does not work. IOW, it's impossible to get ALL of the key/lock pairs mated if at least one was mated the "wrong way." But could you, by mating more than one the wrong way, still get all of them to "fit?" Hmmmm.
-Phil
I used the tool I use to find all of life's problems, Spin.
Here's the output:
I initially didn't have "oneInLock" increment. I started out assuming there would be eight ones.
However, in the more diabolical approach, a lock with all zeroes is okay. If, for example, a key with the value 00000001 were inserted into it, and all the other keys inserted correctly, you'd end up with a 00000000 key that didn't fit the remaining 00000001 lock, and the user (i.e. victim) would have to backtrack to find his/her error. I'm just not sure I want to make the mechanical puzzle that difficult, though. The 5-of-10 code, with 252 possible locks, seems more attractive at the moment, since it does not permit this sort of "garden path" error to occur in the first place.
-Phil
That alters the problem.
As the design stands its trivial to make a master key, which is undesirable property of a lock design!
-Phil
I'm also wondering why the 'keys' need a 'physical fit' like that?
In most locks, you won't know if a key fits before you try to turn it.
but here you end up with keys that can only fit one lock even before 'activation'.
So, Yeah, I'm curious about this one...
-Phil
How would it change things if he keys were allowed to be flipped over, reversing the order of the bits?
When can we buy this puzzle as a box of laser cut plywood keys?
I'm going to offset the teeth in such a way that that can't happen.
-Phil