Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Fastest way to try all passwords

There are $10^4$ different 4-digit codes. If each code takes 4 keypresses to try, then it would take $4*10^4$ keypresses to try all possible codes.

Now the specific codelock i have in mind is of the type that unlocks when the last 4 digits that were pressed are the code, e.g if the code is 0000 one could enter 12351350000 and it would unlock. This implies that to test the codes 0000 and 0001, one needs only 5 keypresses.

How many keypresses does it take to try all the codes on such a codelock?

share|cite|improve this question

marked as duplicate by Henning Makholm, Hans Lundmark, Leonid Kovalev, Chris Eagle, t.b. Aug 17 '12 at 11:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 5 down vote accepted

$10^4 + 3$. See de Bruijn sequences, which exist for all bases and lengths.

share|cite|improve this answer
Thank you, i am very content with this answer. Good day sir! – perserk Jun 16 '12 at 17:00

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