# Smallest N such that writing down integers 1 to N uses a different number of each of the ten digits

As shown here: https://puzzling.stackexchange.com/questions/97696/consecutive-numbers-which-use-all-digits-a-different-number-of-times/97698#97698, there are arbitrarily long blocks of consecutive integers which, when written all down, use each of the ten digits a different number of times. That block can even begin at 1.

What I am looking for is the smallest N such that writing down all the numbers 1, 2, 3, ...,N will use each of the digits 0 to 9 a different number of times. Moreover, can such numbers be characterized in some nice way?

• Well if you you them all, and you each of them a different number of times, you could use one of them once, another one twice, ... Apr 30, 2020 at 19:26

Two adjacent digits appear the same number of times unless one of them occurs in $$N$$. Here $$0$$ is effectively adjacent to $$9$$, not to $$1$$, because numbers don’t have leading zeros, so $$0$$ appears after $$9$$, not before $$1$$.
So we have $$9$$ pairs of adjacent digits to cover, and each digit only covers $$2$$ pairs, so we need at least $$5$$ digits. If this were the whole story, the least admissible $$N$$ would be $$13579$$. But the last digit is special: A last digit $$d$$ only makes $$d$$ and $$d+1$$ have different counts, but not $$d$$ and $$d-1$$, so $$13579$$ leads to the same number of $$9$$s and $$8$$s. So we actually have to cover $$8$$ pairs of digits with the remaining $$4$$ digits, and that only works if we start with $$2$$.
So the next candidate would be $$24689$$. But there’s another special feature of the last digit: If it’s a $$9$$, that means that the penultimate digit $$d$$ gets the same count as $$d-1$$, so we lose one distinction that we need. Thus, we can’t have the $$9$$ in the last digit, so we have to move it up by one.
That leads to $$N=24697$$, and this is indeed the first number of the kind you’re looking for. Here’s Java code that checks this result.