Stop and think how you do it yourself when playing the game.
The player inputs a set of coloured pegs and you compare them against the "solution set" in two ways.
First you look for exact matches: a peg of the right colour in the right place, and you mentally replace each of them with a black peg, removing them from any further consideration:
Solution: R G B Y Y G
Guess: P G Y Y G P
Black: x B x B x x
Sol remain: R B Y G
Guess remain: P Y G P
That's easy - just check colours in matching indexes!
Then you check what is left to find "white" matches: Right colour, wrong place:
Sol remain: R B Y G
Guess remain: P Y G P
White: x W W x
The simplest way to do that is to loop through each of the solution left, and look for a matching colour in what is left of the guess. If you find it, count a White and remove the colour from the Guess - then skip to the next solution index.
Try that on paper, and you'll see what I mean.
Get that all sorted in your head and it's pretty easy to code, and it works for any number of colours, and any number of pegs!