18. Next year, 2022 , has the property that it may be written using at most two different digits, namely 2 and 0 . How many such years will there be between 1 and 9999 inclusive?
SolUtion
927

All of the 99 years 1 to 99 may be written using at most two different digits. Three-digit years (i.e. those between 100 and 999 inclusive) can be written using only one different digit if they are of the form 'aaa', for example 111 or 222 . There are 9 such years. Three-digit years can be written using exactly two different digits $a$ and $b$ if they have any of the three following forms: 'aab', 'aba' or 'abb', where $\mathrm{a}, \mathrm{b}$ are distinct digits and $a \neq 0$. There are 9 possibilities for $a$ and for each there are then 9 possibilities for $b$. Therefore there are $9 \times 9 \times 3=243$ such years.
Four-digit years (i.e. those between 1000 and 9999 inclusive) can be written using only one different digit if they are of the form 'aaaa', for example 3333 or 4444 . There are 9 such years. Four-digit years can be written using exactly two different digits $a$ and $b$ if they have any of the seven following forms: 'aaab', 'aaba', 'abaa', 'aabb', 'abab', 'abba' or 'abbb', where a,b are distinct digits and $a \neq 0$. There are 9 possibilities for $a$ and for each there are then 9 possibilities for $b$. Therefore there are $9 \times 9 \times 7=567$ such years.
Therefore, the total number of such years is $99+9+243+9+567=927$.