Largest number containing every possible $2$-digit string only once?

517 Views Asked by At

How can I easily find the largest number such that every $2$-digit string ($00, 01, 02,...)$ occurs only once (strings can share the same digit, eg. $104507$ contains the strings $45$ and $50$). I do not know where to start to find this number ($99989796959493929190.........09080706050403020100$) contains the strings $99$ and $90$ twice so concatenating all the strings from $00$ to $99$ won't work.

The largest number with every one digit string occurring only once is $9876543210$. Can someone help or explain how this number is impossible to find. Thanks.

1

There are 1 best solutions below

8
On BEST ANSWER

They keyword search you want is 'De Bruijn sequences' - which are quite fascinating!

For your example, the sequence you want is:

99897969594939291908878685848382818077675747372717066564636261605545352515044342414033231302212011009

For an alphabet of $k$ characters (in your case, $10$), any sequence containing all sub-sequences of length $n$ (in your case, $2$) must be at least $k^n + (n-1)$ digits; and a De Bruijn sequence, with the left-most $n-1$ appended to at the right end, has exactly that length.

I like the way De Bruijn sequences connect what seems like a combinatorial problem with a graph theory problem - see the Wikipedia page on the subject. Enjoy!