Find the number of ways, four distinct piles of stones can be made with each pile containing at least 1 and not more than 9 stones, such that the nim-sum of the four piles is zero.
I could only think of, first selecting the three piles in 9 * 9* 9 ways and then filling the last pile with the required number. But then it is tedious to find the undesirable cases where the nim-sum of the first three exceeds 9 or is equal to 0. If there is another way or some coding required, pl tell me.
Here is an outline of what I would do:
If you had numbers 1 through 7, it would be much more convenient, right? You would do as you mentioned, and would only have to consider the undesirable cases where the first three piles add up to 0. This is also easier and there are not too many cases this way. Check it!
Now 8 and 9 are also allowed. If there is at least one of them, then there are at least two of them so that the leftmost digit adds up to zero. Distinguish cases (8,8), (8,9), (9,8), (9,9) as well as where all four are either 8 or 9. The latter cases are easy anyways, and the first cases should not be difficult either (2 piles remain and they should be in 1,...,7 and have some fixed nimsum).
Obviously add up the cases 1 and 2.
Can't guarantee this is the easiest way, but I think dealing with 8 and 9 is what makes this problem nontrivial!