Mastermind question with $1$ repeated color I came across a combinatorics problem related to the game Mastermind. Here's the question:

Suppose your first guess uses $3$ different colors (one color is repeated) and
  its score is one black and $3$ whites. How many different secret codes are
  possible? 

You score a black peg if you get both, the color and position right. You score a white peg if you get only the color right, but in the wrong position. There are $6$ possible colors to choose from, and $4$ positions to place your chosen colors in. Colors can be repeated, such as in this question.
So in the question above, we have $3$ colors and $4$ pegs. Now if one of these $4$ pegs is in the correct position and the other 3 are correct pegs but wrongly arranged, it's just a matter of rearranging them. So in how many ways can you do that?

At least one of the duplicate colour pegs must be in its correct position as otherwise the other two pegs would have to take their places and there couldn't be a black peg.
Once we fix one of the duplicate pegs, the other peg can take either of the two remaining positions, and this already determines the rest. Henc ethere are four possible secret codes (two choices of correct peg times  two rearrangements of the rest).
Concretely, an inital guess of $aabc$ allows only $abca$, $acab$, $baca$, $caab$.
