# puzzle: A spy and the keypad

A spy encounters a keypad that requires a 4 digit PIN. He uses a fine dust to find which keys are used in the combination. He does not know the sequence of keys, nor which ones repeat if any. Obviously if only 3 keys are required one of them is repeated. If 2 keys are required then either 2 keys are repeated twice, or 1 key repeated three times.

The puzzle is for me to design a pin which makes the spies job as hard as possible. Are 4 unique keys the safest, or is have one or more repeating keys better?

1. One digit used = 1 combination
2. Two digits used = 14 combinations = 2^4-2
3. Three digits used = ? combinations
4. Four digits used = ? combinations

Can someone do the math and come up with the possible combinations that use exactly 3 and 4 keys, no more or less. My intuition is that the repeating keys will increase the number of combinations more than used all 4 keys for the pin.

PS. For the two digits (if they are X, Y) then the combinations are:

XXXY, XXYX, XXYY,
XYXX, XYXY, XYYX, XYYY,
YXXX, YXXY, YXYX, YXYY,
YYXX, YYXY, YYYX

• Tell the folks that when entering the code, they should always press on a few random keys as well. This way the spy can't figure out which keys below to the code! Muhahaha. Apr 10, 2013 at 17:04
• I once lived in a building with a keypad-activated lock at the main entrance, which had a peculiar characteristic: it beeped when each key was pressed, at a frequency that depended on the key pressed. So your typical spy could dispense with the fine dust... Apr 10, 2013 at 17:21
• @AsafKaragila - and gloves haven't been invented yet. Apr 10, 2013 at 20:02
• @ja72: It's too hot for gloves in Israel. :-) Apr 10, 2013 at 20:17

• Can you elaborate a little more on the logic. I don't quite follow on how you arrive at $4!$ and $\frac{3}{2}4!$. Apr 10, 2013 at 20:06