Number substrings
Given a target integer, what's the fewest digits needed for an integer in a given base to contain all integers from 0 to the target as substring?
Here's an interesting question: given a target integer , what's the smallest number of (significant) digits an integer must have in a given base so that it contains as substrings all integers from to ?
Let's clarify with some examples, and assume for simplicity that we're working in base 10.
Obviously, for , the minimum number of digits to have all numbers from to is , since all numbers from to are (distinct) single-digit numbers, so, for example, for you need a -digit number at least ( would do, but so would ; the actual number doesn't matter, we only care about the number of digits).
With two-digit numbers, things become more interesting. For example, the same also has as a substring, so it works for too. It doesn't work for though —and for that you can prove that you need at least an -digit number because you need a repeated digit (for example, ). With you want to have substrings , and while the can share its final digit with either the or the , it can't do both, so it will need to be something like , a 12-digit number.
The same argument can be repeated up to (), a 19-digit number, and even for you'll need to at least add a after the existing 2 () since you can't share the 0 used for and … which is a pity, because this splits the from the that could be otherwise be used for , so we need an extra digit (). Similarly, we can't easily recycle the two s we have to get to (we need , and ), so we'll need another digit (, a 22-digit number), but then for we can't just add one digit, because we need both another 2 and another 3: needs a 24-digit number, and the same “+2” growth is needed for all numbers up to , leading to the monstrous 36-digit number .
Things then slow down again: for we just need to add a single digit, , and this same number works for , but not for because we split the 3 from the 2 again …
How does the pattern flow then as grows larger? On the one hand, there should be more opportunities to use digits for multiple purposes: on the other, you need more combinations.
Is there some kind of law that can describe the pattern? Are there more opportunities to find numbers with less digits if they are rebuilt from scratch for the target , or if they are built with small changes from the previous one(s)?
UPDATE #1: a discussion thread on the Fediverse with @mau@frenfiverse.net mentions that the number of digits needed is monotonic non-decreasing. This is obvious, but just in case here's a short proof.
Let be the function that maps the target number to the minimum number of digits needed in bases . This means that if then there is an integer with (significant) digits in base that includes as substrings all integers from to . Let's call such a number a -digit representative of the target in base . (Note that as exemplified in the beginning, there may be multiple representatives.)
Now consider . If must be because by definition of there is an integer with significant digits in base that includes as substrings all integers from to , which includes all integers from to : if was strictly less than , we could use the -digit representative of also for .
@mau also provides an example sequence of representatives in base 2, but I think it can be improved a little. Remember that the integers in base 2 go: 0, 1, 10, 11, 100, 101, 110, 111, 1000, … and a sequence of representatives could be: 0, 10, 10, 110, 1100, 101100 (@mau proposes 110100) 101100 (ditto), 1011100, 10111000, …
It doesn't look like OEIS has anything like this, so it might be really worth exploring this better.
The one thing that seems to emerge at least with small numbers and bases 2 and 10 is that . Does this hold for larger targets? Does it all in all bases? (I'm particularly curious about the latter for odd balanced bases.)
And for those that enjoy pure math the most when it doesn't seem to have any applications, I strongly doubt somebody will ever find a practical application to this, other than in the game I play with my kids to avoid car boredom.
UPDATE #2: new discussion thread on the Fediverse. @wqferr@mathstodon.xyz points out that this problem may be related to (generalized) superpermutations, especially when , and @mrdk@mathstodon.xyz relates it to de Bruijn sequences. There are are still some significant differences in the rules that the representative should follow that have a significant impact on the number of digits, but we seem to be getting somewhere.