Exercise 5. A number has been written on the board. At each step, we add to it the largest of its digits (for example, if 142 is written, the next number will be 146). What is the maximum number of odd numbers that can be written consecutively by proceeding in this way?
Solution to Exercise 5 The answer is 5. Suppose we start with an odd number $n$. We denote $n_{i}$ as the $i$-th number written, with $n_{1}=n$. Let $c_{i}$ and $d_{i}$ be the largest digit and the units digit of $n_{i}$. If $c_{1}$ is odd, then $n_{2}=n_{1}+c_{1}$ is even, and we have only written one odd number. Note also that $c_{1}$ cannot be equal to 0.

If $c_{1}=2$, then $d_{1}=1$. We have $n_{2}=n_{1}+2$, so $c_{2}=3$ and $d_{2}=3$, and $n_{3}=n_{2}+3$ is even. The third number written is therefore even.

If $c_{1}=4$, then $d_{1}$ can be 1 or 3. If $d_{1}=1$, then $n_{2}=n_{1}+4$ so $c_{2}=5$ and $d_{2}=5$, so $n_{3}=n_{2}+5$ is even. If $d_{1}=3$, then $n_{2}=n_{1}+4$ so $c_{2}=7$ and $d_{2}=7$, so $n_{3}=n_{2}+7$ is even.

If $c_{1}=6$, then $d_{1}$ can be 1, 3, or 5. In the first two cases, we get $n_{3}$ even as before. If $d_{1}=5$, then $n_{2}=n_{1}+6$ so $d_{2}=1$. Moreover, the largest digit either remains the same $\left(c_{2}=6\right)$ or increases by 1 $\left(c_{2}=7\right)$. In the second case, $n_{3}=n_{2}+7$ is even. In the first case, $n_{3}=n_{2}+6$ so $d_{3}=7$ and $c_{3}=7$ so $n_{4}=n_{3}+7$ is even.

If $c_{1}=8$, then $d_{1}$ can be 1, 3, 5, or 7.

- if $d_{1}=1$, we get $c_{2}=d_{2}=9$ so $n_{3}$ is even.
- if $d_{1}=3$, then $d_{2}=1$ and $c_{2}$ can be 8 or 9. In the second case $n_{3}$ is even, and in the first we are reduced to the previous case $\left(c=8, d=1\right)$ so $n_{4}$ is even.
- if $d_{1}=5$, then $d_{2}=3$ and $c_{2}$ can be 8 or 9. In the second case $n_{3}$ is even, and in the first we are reduced to the previous case $(c=8, d=3)$ so $n_{4}$ or $n_{5}$ is even.
- if $d_{1}=7$, then $d_{2}=5$ and $c_{2}$ can be 8 or 9. In the second case $n_{3}$ is even, and in the first we are reduced to the previous case $(c=8, d=5)$ so $n_{4}$ or $n_{5}$ or $n_{6}$ is even.

It is therefore impossible to write 6 consecutive odd integers. However, if we start with 807, we will write successively $807, 815, 823, 831$, and 839, so we can write 5 consecutive odd integers.