Play the Game Mastermind

This function plays the game Mastermind.

Mastermind is played with small pegs of different colors. One player creates a secret code, which consists of a sequence of colored pegs. (The standard game has four pegs in the code and six colors to choose from, but other variations exist.) The other player attempts to decipher the secret code by making guesses at the sequence. After each guess, the first player assigns a score to the guess by using a second set of pegs that are black and white. The score is one black peg for each peg in the guess that matches up exactly with a peg in the secret (same color, same location) and ...

Get Find the Bug A Book of Incorrect Programs now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.