I would like to know if there is an expression for the number of n-tuples of $\mathbb{Z}$, where each component is an integer between $0$ and $2$, and the sum of the components is less than or equal to some number $d \in [0,2n]$.
I am also interested if this expression could be generalised for integer n-tuples with components between $0$ and $q$, with the sum of the components being less than or equal to some given number $d \in [0, (q-1)n]$, but would appreciate an answer for just the case $q=3$.
I know from (a slight alteration of) this post that the number of n-tuples of non-negative integers with the sum of components less than or equal to $d$ is equal to $d+n \choose n$. But I'm not sure if this information helps.
The answer can be found with the principle of inclusion exclusion, by taking all $\binom{n+d}{n}$ vectors, then subtracting for each coordinate the $\binom{n+d-q}{n}$ vectors where the coordinate is too large, then adding back in the doubly subtracted vectors, etc. The result is $$ \bbox[5px, #fbfbfb, border: solid black 2px]{\sum_{k=0}^n (-1)^k\binom{n}{k}\binom{n+d-qk}{n}.} $$