Thursday, 16 May 2013

password - Shortest Number Containing the Numbers 1-100?


Exactly what the title says: What is the shortest (fewest digits) number you can find such that somewhere in it, you can find each number 1- 100?


My thinking for this puzzle is you have an electric numeric lock that can have any code from 1-100 and you want to try all possibilities in the shortest time. (Assuming you don't have to push enter or whatever).


For examples:


1-10 can be 1023456789


1-11 can be 11023456789


1-12 can be 110123456789


...


Also, is there some sort of formula that can extend this to other numbers (1-1000, 1-50, ...)



Answer




If you use a decimal De Bruijn sequence of order 2, you get a string of 100 digits that contains every possible substring of length 2 - that is, every possible two-digit number, although you need one last digit to account for the wraparound, bring the total to 101.


Suppose further that the first three digits are "100", we get 100 without adding any additional digits. This must be possible because any valid de Bruijn sequence can be "rotated" so that the second and third digits are identical, and then the digits remapped so that the first digit is 1 and the next two digits are 0.


So the shortest number that fits your criteria is 101 digits long.


No comments:

Post a Comment

Understanding Stagnation point in pitot fluid

What is stagnation point in fluid mechanics. At the open end of the pitot tube the velocity of the fluid becomes zero.But that should result...