permutation with repetition subset How many distinct strings of length 4 can be generated with $c,b,b,a,a,d$
Through a script I know that there are 102 such possibilities. 
My Attempt
Case 1: using only one 'b' and one 'a'. This can happen in 4! number of strings.
Case 2: using two 'a' and no 'b'. 12
Case 3: using two 'b' and no 'a'. 12
Case 4: Using two 'a' and one 'b'. 12*2
Case 5: Using two 'b' and one 'a'. 12*2
Case 6: Using two 'a' and two 'b' only. 6
Adding numbers from all the cases I get 102 which actually complies with the script findings. 
Question
Is there any better way to do this, a formula?
 A: The coefficient of $x^n/n!$ in the product $$(1+x)^2(1+x+x^2/2!)^2 = 1+4x+ 7x^2+ 7x^3+ \frac{17}{4}x^4+\frac{3}{2}x^5+\frac14 x^6$$ counts the number of strings of length $n$ you can make with that multiset of letters. The coefficient of $x^4/4!$ is $4! (17/4)=102.$ 
For a more general set of letters you get a factor of $(1+x+x^2/2!+\cdots+ x^k/k!)$ for a letter which is allowed to appear up to $k$ times.
A: You can do it using only three cases:  The string $4$ has either two pairs of repeated letters (i.e., is a permutation of $aabb$), or one pair of repeated letters, or no repeated letters.  There are ${4\choose2}=6$ possibilities for the first case, and $4!=24$ possibilities for the third.  As for the second case, there are $2$ choices for the pair of repeated letters, ${4\choose2}=6$ ways to position them, $3$ choices for what goes in the first remaining open position, and $2$ choices for what goes in the final spot, for a total of $2\cdot6\cdot3\cdot2=72$ possibilities, and this gives an overall sum of
$$6+72+24=102$$
A: This problem and any problems similar to this can be solved by
Using Generating Functions to Find Combinations, Count of Combinations and Count of Linear Permutations as explained in the following url
http://stemandmusic.in/maths/combinatorics/combGFCLP.php
As per the formulae given in the above url,
the Generating Function for combinations of Letters
containing upto two a's, two b's, one c and one d can be formed by multiplying following polynomials
$(a^0 + a^1 + a^2)(b^0 + b^1 + b^2)(c^0 + c^1)(d^0 + d^1)$
on multiplying the above four polynomials the terms
which have a total power of 4 are and the number of ways
each can be arranged are
$abcd$ : Can be arranged in 4! (=24) number of ways
$a^2b^2$ : Can be arranged in $\frac{4!}{2!2!}$ (=6) number of ways
$a^2bc$ : Can be arranged in $\frac{4!}{2!1!1!}$ (=12) number of ways
$a^2bd$ : Can be arranged in $\frac{4!}{2!1!1!}$ (=12) number of ways
$a^2cd$ : Can be arranged in $\frac{4!}{2!1!1!}$ (=12) number of ways
$ab^2c$ : Can be arranged in $\frac{4!}{2!1!1!}$ (=12) number of ways
$ab^2d$ : Can be arranged in $\frac{4!}{2!1!1!}$ (=12) number of ways
$b^2cd$ : Can be arranged in $\frac{4!}{2!1!1!}$ (=12) number of ways
Hence the number of distinct strings of length 4 that can be generated with $c,b,b,a,a,d$ are $102$
