I have this question that I found in a past paper. I’ve solved it, but would there be a more efficient way to solve this? Here is the question:
Let $x$ be the year that is $P$ years before $2017$. If the sum of the digits of $x$ is equal to $P$, how many such $P$ exist?
I have derived a few things, most of them pretty obvious:
- $P$ and $x$ are integers.
- $P$ must be less than or equal to 28, because the year with the greatest sum of digits is 1999, with a digit sum of 28
- Because of 2., $x$ has a range of 1 to 28.
- $x$ can only be a 4-digit number.
Now, all I did was to start from 1 and go all the way back to 28 years, substituting values for $x$ and $P$. I feel like this is very inefficient. Is there a better way to do this?