Code Breaker — Color Code Guessing Game
Guess the secret 4-color code in 10 tries. Black pegs = right color & place; white = right color wrong place.
How to play
- Click color swatches to build a 4-color guess, then hit 'Submit Guess'.
- Black peg (B) = right color in the right position.
- White peg (W) = right color but wrong position.
- Use the feedback from each guess to narrow down the secret code in 10 tries.
- Click 'Clear' to remove the last color, or 'New Game' to start over.
Crack the 4-color secret code in 10 tries. Black pegs (B) = correct color in correct position. White pegs (W) = correct color in wrong position.
How it works
Code Breaker is a logic deduction game based on the classic board game Mastermind. A secret code of four colored pegs is chosen at random, and your task is to identify it in ten guesses or fewer. After each guess you receive feedback: a black peg for every color that is both correct and in the right position, and a white peg for every color that is correct but in the wrong position.
The feedback tells you about the multiset of matching colors but does not say which specific positions earned which peg. You must track multiple hypotheses simultaneously and eliminate possibilities with each clue.
A strong opening strategy is to guess two colors twice each (e.g., Red Red Blue Blue). This gives you precise information about how many reds and blues are in the code. Donald Knuth proved that a minimax strategy can always solve the 6-color 4-peg version in five moves or fewer, so ten guesses is very generous.
This game is ideal for practicing systematic hypothesis elimination, similar to skills used in scientific reasoning and software debugging.
Worked example
Narrow down the code in three guesses
- Guess 1: Red Red Blue Blue. Suppose you get 1 black, 1 white.
- You know the code has exactly one red and one blue, but positions need adjusting.
- Guess 2: Red Green Blue Yellow — move red and blue, add two new colors.
- Suppose you get 2 blacks — two positions are now locked.
- Guess 3: Adjust the remaining two positions based on which spots earned blacks in guess 2.
By guess 4 or 5 you have enough information to state the exact code.
Common mistakes to avoid
- Assuming a white peg means the color is definitely not in that specific column — it just means the color is somewhere else in the code.
- Repeating a color in your next guess after getting zero pegs for it — zero pegs mean that color is not in the code at all.
- Ignoring multiset arithmetic: if your guess has two reds and you get one black, the code has exactly one red, not necessarily two.
Key terms
- Black peg
- Correct color in the correct position.
- White peg
- Correct color present in the code but placed in the wrong position.
- Minimax strategy
- A guessing approach that minimizes the worst-case number of guesses needed to guarantee a solution.
Frequently asked questions
- What do B and W mean?
- B (black peg) = correct color AND correct position. W (white peg) = correct color but wrong position.
- Can colors repeat in the secret code?
- Yes — the same color can appear more than once in the secret code.