Exam question: Let $D(d_{1},d_{2},...,d_{k})$ denote the number of derangements of a multiset where there are $d_{i}$ copies of elements of the $i$-th kind, for $i=1,...,k$. This means the arrangements of elements of this multiset in a sequence such that in the first $d_{1}$ positions there is no element of the first kind, in the next $d_{2}$ positions there is no element of the second kind, and so on. For example: $D(1,2)=0, D(2,2)=1, D(1,1,2)=2$. The only derangements of the multiset $\{a,b,c,c\}$ are $\langle c,c,a,b \rangle$ and $\langle c,c,b,a \rangle$.
Find $D(2,2,2,3)$. The WolframAlpha website might be useful for calculations.
Initially, I was thinking about the principle of inclusion and exclusion:
$ \frac{9!}{2! \cdot 2! \cdot 2! \cdot 3!} - 6 \binom{8}{1} \binom{7}{2} \binom{5}{2} - 3 \binom{8}{2} \binom{6}{2} \binom{4}{2} + \left( 3 \cdot 2 \cdot 2 \cdot \binom{6}{1} \cdot \binom{6}{1} \cdot \binom{5}{2} + 3 \binom{7}{2} \binom{5}{2} \right) + \left( 3 \cdot 3 \cdot 2 \cdot \binom{7}{1} \binom{6}{2} \binom{4}{2} + 3 \cdot \binom{7}{1} \binom{6}{2} \binom{4}{2} \right)-... $
Where in the first parenthesis I subtract situations when one of the letters a, b, c is in the wrong position, in the second parenthesis when d is in the wrong position, in the third parenthesis pairs but without the letter d and dividing into situations when the pair consists of two identical letters (both letters a, a are in the wrong positions) or two different ones (e.g., a, b). The fourth is the same as the third but is a case for pairs with the letter d. The problem is that there are still seven cases to consider left, and each subsequent one is worse.
Brute force approach gives me $D(2,2,2,3)= 564$.
I have found similar questions Derangement formula for multisets, Derangements of a multiset with "don't cares"? and I tried using the given formula but it doesn't seem to work: WolframAplha.
How can one count these combinations?
The formula given at the question you linked, Derangement formula for multisets, works just fine. You just incorrectly inputted the formula into Wolfram Alpha. Here is the correct input, which now agrees with your brute-force result:
https://www.wolframalpha.com/input?i2d=true&i=Sum%5BSum%5BSum%5BSum%5BPower%5B%5C%2840%29-1%5C%2841%29%2Ca%2Bb%2Bc%2Bd%5D%5C%2840%292+choose+a%5C%2841%29%5C%2840%292+choose+b%5C%2841%29%5C%2840%292+choose+c%5C%2841%29%5C%2840%293+choose+d%5C%2841%29+Divide%5B+%5C%2840%29%5C%2840%292-a%5C%2841%29%2B%5C%2840%292-b%5C%2841%29%2B%5C%2840%292-c%5C%2841%29%2B%5C%2840%293-d%5C%2841%29%5C%2841%29%21%2C%5C%2840%292-a%5C%2841%29%21%5C%2840%292-b%5C%2841%29%21%5C%2840%292-c%5C%2841%29%21%5C%2840%293-d%5C%2841%29%21%5D%2C%7Bd%2C0%2C3%7D%5D%2C%7Bc%2C0%2C2%7D%5D%2C%7Bb%2C0%2C2%7D%5D%2C%7Ba%2C0%2C2%7D%5D