Solution

The Number That Describes Itself

Show the problem again

Find the ten-digit number d₀d₁d₂…d₉ such that, for every i from 0 to 9, the digit dᵢ equals the number of times the digit i appears in the number itself. (For example, in 2020 in base 4, d₀ = 2 says there are two zeros, d₁ = 0 says no ones, and so on.) The number is unique. Give it as a ten-digit integer.

Worked solution

Two counts help. The digits $d_0, \dots, d_9$ count all ten positions, so $\sum d_i = 10$. Adding up the values of all ten digits gives the same total in another way: $d_i$ of the digits equal $i$, so $\sum i\,d_i = 10$ as well. Subtracting, $\sum (i - 1) d_i = 0$, that is, $$d_0 = d_2 + 2d_3 + 3d_4 + \dots + 8d_9.$$ The right side adds $(v - 1)$ for every digit of value $v \ge 2$ that appears in the number. Let $k = d_0$. It is at least 1, since $d_0 = 0$ would itself be a zero. If $k = 1$, the right side says exactly one digit 2 appears and no larger digit; the other eight nonzero digits are then 1s, so $d_1 = 8$, a contradiction. If $k = 2$, then $d_0 = 2$ itself already contributes 1, so it is the only digit above 1; the other seven nonzero digits are 1s, and $d_1 = 7$, again a contradiction. If $k \ge 3$, then the digit $d_0 = k$ contributes $k - 1$ and exactly one more digit equal to 2 appears, with every other nonzero digit equal to 1. So $d_k = 1$ and $d_2 = 1$ (one 2 appears), and the single 2 must sit at position 1: $d_1 = 2$. The nonzero digits are therefore $d_0 = k$, $d_1 = 2$, $d_2 = 1$, $d_k = 1$, which do contain exactly two 1s, so the number of zeros is $10 - 4 = 6 = k$. The number is **6210001000**: six zeros, two ones, one two and one six. A computer search over all digit strings agrees that it is the only one.

Source: Self-describing numbers are a classic of recreational mathematics (discussed by Martin Gardner among others); this formulation written for AxiomIQ.