In a four-letter code, each letter is A, B, C, or D. How many possible codes are there, if each letter can be used at most twice?
It is always much easier to list the combinations first and convert them to permutations:
{A, A, B, B} | {A, A, B, C} | {A, A, B, D} | {A, A, C, C} | {A, A, C, D} | {A, A, D, D} | {A, B, B, C} | {A, B, B, D} | {A, B, C, C} | {A, B, C, D} | {A, B, D, D} | {A, C, C, D} | {A, C, D, D} | {B, B, C, C} | {B, B, C, D} | {B, B, D, D} | {B, C, C, D} | {B, C, D, D} | {C, C, D, D} = 19 combinations.
Their permutations =[6 x 6] + [12 x 12] + 24 =36 + 144 + 24 =204 permutations, or number of possible codes