99tools

Code Breaker

runs in your browser

The classic colour-code deduction game: break a hidden code of 4 or 5 pegs in 10 or 12 guesses from right-place and wrong-place clues. Solo or two players.

Players
Pegs
Colours

Changing a setting starts a new game. 10 guesses to break a code of 4 pegs from 6 colours, where a colour can appear more than once.

board

10 guesses left

A code of 4 pegs is drawn at random when you make your first guess. After each guess, a filled dot means a peg is the right colour in the right place, and a hollow dot the right colour in the wrong place — but not which peg.

Guess 1

Or type 1–6, Backspace to take one back, Enter to play.

how to play

  • right colour, right place
  • right colour, wrong place

The dots never say which peg they mean: that is the puzzle. Each peg of the code answers for one peg of your guess only, so guessing four reds when the code has one scores one dot, not four.

about this tool

Break the hidden code

A row of coloured pegs is hidden. Guess a row of your own, and the game tells you two things: how many of your pegs are the right colour in the right place (a filled dot), and how many are the right colour in the wrong place (a hollow dot). It never says which pegs those are — working that out is the game. Break the code within ten guesses — twelve on the hardest board.

Each peg carries its number as well as its colour, so the game can be played by anyone who finds colours hard to tell apart, and the number keys put a colour in the next place: Backspace takes one back, Enter plays the guess.

How the dots are counted

Each peg of the code answers for one peg of your guess only. Exact matches are counted first; after that, a colour scores a hollow dot as many times as it is left over in both rows. If the code is red, blue, blue, yellow and you guess blue, blue, blue, blue, you get two filled dots and nothing more — the third and fourth blue have nothing left to match.

Settings

  • Pegs: four, the classic, or five.
  • Colours: six, or eight for a much larger set of codes.
  • Colours can repeat: on, a colour may appear more than once in the code; off, each colour once at most, which makes it easier.

Four pegs of six colours with repeats is 1,296 possible codes. Five of eight is 32,768, so that board gives twelve guesses instead of ten. Changing a setting starts a new game.

Two players

Choose two players and one of you picks the code while the other looks away, then presses Hide the code and hand over. The code is drawn fairly by the page in solo games; in two-player games it is whatever the setter chooses, and nothing is shown until the game ends.

The hint

Show how many codes still fit counts every code that would have given all the answers so far. It does not say which, but it is an honest check on your reasoning: when it reaches one, you have it. With four pegs of six colours, every code can be broken in five guesses at most — Donald Knuth showed how in 1977.

Copy result gives the game as rows of dots, with no colours, so it can be shared without giving the code away. For other puzzles with one answer, try Crowns or Sudoku; to play someone at the table, 4 in a row.

questions

How do you play Code Breaker?
A code of four pegs, each one of six colours, is hidden. Guess a row of four; the game answers with a filled dot for every peg that is the right colour in the right place and a hollow dot for every one that is the right colour in the wrong place — without saying which pegs they are. Use the clues to narrow it down and break the code within ten guesses.
How are the dots counted when a colour repeats?
Each peg of the code can answer for one peg of your guess only. Exact matches are counted first; then a colour scores a hollow dot as many times as it is left over in both the code and the guess. So if the code has one red and you guess four, you get one dot, not four.
Can two people play?
Yes. Choose two players: one picks a code while the other looks away, then hides it and hands the phone or laptop over. The other has the usual number of guesses to break it. Swap and see who breaks the other’s code faster.
What makes it harder?
Five pegs, or eight colours, or both. Five pegs of eight colours is 32,768 possible codes, against 1,296 for the classic four of six, so that board gives twelve guesses instead of ten. Switching repeats off makes it easier: each colour can then appear once at most.
What does the hint show?
How many codes still fit every answer you have had so far. It does not say which, but it is a check on your reasoning: a guess that could not be the code cannot win on that turn, and when the number reaches one, you know it.
Can it be won every time?
With four pegs, six colours and repeats, yes: every code can be broken in five guesses or fewer with the right strategy, as Donald Knuth showed in 1977. Most people take five or six; the board gives ten.