I'm trying to index $M$ squares that can each have $N$ colours. The order the colours appear in does not matter, it just matters how many of each colour there are.
So say $N=2$ and $M=2$ and the colours are red(R) and blue(B). This results in the following possible states for our squares: $RR, RB, BR, BB$. If we want to map those to how much of each colour there are this results in $02, 11, 11, 20$, so the first digit represents the amount of blue's and the second the reds.
It's easy to see that the digit sum of this representation is always equal to $M$. Now say $N$ and $M$ are very large. We can represent each colour state as an $N$ length number of base $M$. However, I want to store some information about each possible colour state. Therefore we should introduce an ordering in the colour states so a mapping is possible. We can simply order by size: $[02,11,20]$.
Now the actual question is as follows: given the number $20$, how many numbers below $20$ are there that have the same digit sum? Because that equals $2$, which is the exact position I need to look in my information array. A possible strategy is building a lookup table by just enumeration all possibilities, but I want to know if there is a "smarter" way. How many numbers with equal digit sum are there below N? Of course, if someone knows a smarter way to label my colour states, that would also be accepted, but the other question remains interesting as well.