## The dynamics of a trick ### The case with four or more digits

Which properties does this dynamical system have when we consider numbers with four or more digits? Let $$N_{D}$$ be the set of natural numbers with $$D$$ digits from $$\{0,1,...,9\}$$, where we allow zeros at the left; and let $$i_{D}:N_{D}\rightarrow N_{D}$$ be the function defined as follows: $$0$$ maps to $$0$$ and each nonzero $$x$$ in $$N_{D}$$, written in base $$10$$ and represented by $$D$$ digits $x=x_{D-1}...x_{m}x_{m-1}...x_{1}x_{0},$ with $$m=\mbox{maximum}\{i: 0\leq i\leq D-1 \land x_{i}\neq 0\}$$, is mapped to the natural $i_{D}(x)=x_{0}x_{1} ...x_{m-1}x_{m}...x_{D-1}$ obtained by reversing the order of the digits of $$x$$.

If $$f_{D}$$ designates the function $$N_{D}\rightarrow N_{D}$$ defined by $$f_{D}(x)=\left|x-i_{D}(x)\right|$$, then all numbers in the image of $$f_{D}$$ are multiples of $$9$$ (and, when $$D$$ is odd, they are simultaneously multiples of $$9$$ and $$11$$).

In fact, that image is reduced to $$\frac{19^{\frac{D}{2}} +1}{2}$$ elements if $$D$$ is even, and to $$\frac{19^{\frac{D-1}{2}} +1}{2}$$ elements if $$D$$is odd (see proof). Moreover, since $$N_{D}$$ is finite, each orbit of $$f_{D}$$ must end in a cycle whose elements are in the image of $$f_{D}$$.

The table below contains some information about the dynamics of $$f_{D}$$ for $$1\leq D\leq 11$$: the numbers of cycles, the corresponding periods and, for $$1\leq D\leq 7$$, the maximum preperiods.

$$D$$ Number of cycles Periods Maximum preperiod [Period; Number of cycles for each period]
$$1$$ $$1$$ $$1$$ $$1$$ $$[1; 1]$$
$$2$$ $$2$$ $$1,$$ $$5$$ $$2$$ $$[1; 1],$$ $$[5; 1]$$
$$3$$ $$2$$ $$1,$$ $$5$$ $$2$$ $$[1; 1],$$ $$[5; 1]$$
$$4$$ $$5$$ $$1,$$ $$2,$$ $$5$$ $$12$$ $$[1; 1],$$ $$[2;1],$$ $$[5; 3]$$
$$5$$ $$5$$ $$1,$$ $$2,$$ $$5$$ $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