Deductive Code Cracking

Codebreaker

An elegant deductive color puzzle. Crack the secret 4-color code within 10 attempts. Click peg slots to place colors, or tap the palette to quick-fill!

Colors: 6
Repetitive Colors
Attempt1 / 10
StatusDECODING
Moves0
Time0:00
1
2
3
4
5
6
7
8
9
10
Select Color:

💡 Auto-Fill: Tap a color to place it in the next empty slot of Row 1.

Deductive Cryptanalysis Manual

How to Master Codebreaker Puzzles

The Official Codebreaker & Mastermind Rules

Codebreaker is a modern web-based adaptation of the classic paper-and-pencil game Bulls and Cows, popularized as the board game Mastermind in the 1970s.

The game begins with the computer generating a secret sequence of 4 colored pegs chosen from 6 available colors. By default, duplicate (repetitive) colors are allowed in the secret sequence (making it more challenging). However, you can toggle Repetitive Colors off to ensure all 4 hidden pegs are completely unique, which is a great option for a more strategic and relaxed 10-attempt solving experience!

Your objective is to guess the secret code in 10 rows or fewer. Every guess is evaluated and receives feedback:

  • Green Glow Pegs: The number of pegs that are correct in both color and grid position.
  • Light Silver Pegs: The number of pegs that are correct in color, but placed in the wrong position.
  • The feedback pegs are displayed in a 2x2 grid in no particular order, so you must use deduction to align colors with positions!
The Legendary 5-Guess Winning Strategy (Knuth Minimax Algorithm)

In 1977, the legendary computer scientist Donald Knuth published a mathematical paper proving that Codebreaker (with 4 slots and 6 colors) can be solved in 5 guesses or fewer!

To implement his elite minimax strategy, follow these rules of thumb:

  • The Optimal Opening Guess (AABB): Always start with a double-duplicate pattern, specifically two pegs of one color and two pegs of another (e.g., [Red, Red, Blue, Blue]). Knuth demonstrated that starting with four different colors (e.g., [Red, Blue, Green, Yellow]) does not guarantee a win within 5 moves.
  • Eliminate the Impossible: For your subsequent moves, only consider color combinations that would yield the exact same feedback if they were the secret code. If you have 1 Green feedback on a guess, any candidate secret code that would yield 0 or 2 Green feedback against your guess is mathematically impossible and can be eliminated!
  • The Minimax Pivot (Worst-Case Reduction): Choose the next guess that minimizes the maximum number of remaining possibilities. Sometimes this means submitting an "impossible" guess to act as a probe—by testing it, you guarantee the elimination of a massive chunk of remaining candidates regardless of the feedback received.
How Duplicate Colors impact Feedback Peg Math

One of the most common points of confusion in Codebreaker is how duplicate colors are scored. To protect deductive integrity, our system uses a strict two-pass matching algorithm:

Imagine the secret code is [Red, Red, Blue, Green] and your guess is [Red, Blue, Blue, Blue]:

  1. First Pass (Exact Matches): The first peg (Red) and third peg (Blue) match perfectly in both color and position. This yields 2 Green (Exact) pegs. These matched pegs are now locked.
  2. Second Pass (Color-Only Matches): The second peg of your guess is Blue. Since the only Blue peg in the secret code was already matched exactly in step 1, this Blue peg does not receive any partial credit. This prevents duplicate colors in your guess from getting "double points"!
  3. Thus, the final feedback for this guess is exactly 2 Green pegs and 0 Silver pegs.

Codebreaker: The Mastermind-Inspired Logic Puzzle

Codebreaker is a brilliant deduction puzzle heavily inspired by the classic 1970s board game Mastermind (which itself evolved from an older pencil-and-paper game called Bulls and Cows). The objective is to decipher a secret code consisting of four colored pegs within 10 attempts.

How to Play Codebreaker

The computer will randomly generate a secret code consisting of four colors. In our version, colors can repeat. It is your job to guess the exact colors and their correct positions.

After you submit a guess, the game provides you with feedback using small indicator pegs:

  • Black Peg (Hit): Indicates that one of your guessed colors is correct AND in the correct position.
  • White Peg (Blow): Indicates that one of your guessed colors is correct, but it is in the WRONG position.
  • Empty (Miss): The color is completely wrong and is not part of the secret code.

Note: The position of the feedback pegs does not correspond to the position of the colors in your guess. They only tell you the total number of hits and blows.

Advanced Code-Breaking Strategies

To consistently crack the code within 10 turns, you must employ strict logical deduction:

  • The Baseline Strategy: A common opening move is to guess two pairs (e.g., Red-Red-Blue-Blue). This quickly tells you if those colors exist in the code while testing multiple positions simultaneously.
  • Isolating Colors: If you receive one Black peg on your first guess, change three of the colors to something completely new on your next guess, while keeping one color the same. This helps isolate which color was the correct hit.
  • The Process of Elimination: If you guess four distinct colors and receive zero feedback pegs, you have gained massive information. You can now completely eliminate those four colors from all future guesses.

Benefits of Playing Codebreaker

Codebreaker requires intense focus, systematic elimination, and robust deductive reasoning. It forces players to hold multiple hypotheses in their mind simultaneously and test them methodically. It is a superb educational tool for teaching logic and problem-solving to kids and adults.