# How many codes in mastermind can have 2 and 3 different colours if 4 pins and 8 colors are used

*print*Print*list*Cite

### 1 Answer

To create a code with 4 pins and 8 colors each of the pins can have any of the 8 colors. The number of codes has to be determined that can be created using 2 and 3 different colors.

When 2 colors are used: 2 colors A and B can be chosen from the group of eight in 8P2 = (8!)/(8-2)! = 8*7 = 56 ways. Each of pins can take any of the two colors; the only option not allowed is that all the 4 pins are color A or color B. This can be done in 2^4 - 2 = 14 ways. Multiplying this by 56 gives the total number of codes possible. The number of codes where 2 colors are used is 14*56 = 784

When the codes are created using 3 colors, 3 colors have to be chosen from the group of 8. This can be doe in 8P3 = 8!/(8 - 3)! = 336 ways. Each of the pins can take any of the 3 three colors that have been selected; the option not be allowed being 3 or 4 pins have the same color. This can be done in 3^4 - 3 - 3*2 = 72 ways. The total number of codes that can be created is 72*336 = 24192. The sum of the number of codes with 2 colors and those with 3 colors is 24976

**The number of codes that can be created with 2 and 3 different colors is 24976.**

**Sources:**