Clever Quest Lab Games

Code Breaker

Work out the hidden code of coloured pegs. Every guess tells you how many pegs are exactly right and how many have the right colour in the wrong place.

NormalLevel
–Guess
OffCodes left
0Wins

Colors

filled dot: right color, right hole ring: right color, wrong hole

1–8 place a color   ← → move   ↑ ↓ change color   Backspace clear   Enter check   F full screen

Keys: 1 to 8 place a color in the selected hole, Left and Right arrows move between holes, Up and Down change the color, Backspace clears, Enter checks the row.

Runs on your device. Nothing you type or record is uploaded. Keeps working without a connection while the page is open. Works with touch. Saves your level, the Codes left and Symbols settings, and your stats for each level on this device.

Added · Updated : Knuth result dated 1976 and an unsourced average number of guesses removed

How to play

The computer picks a secret code of coloured pegs and hides it in the top row of the board. Your task is to find the exact colours and their order. Fill the highlighted row with a guess and press Check. Next to the row you get the answer: a filled dot for every peg that has the right colour in the right hole, and a ring for every peg that has a right colour in the wrong hole. The same answer is also written as two numbers. The dots are always sorted, so they never tell you which of your pegs they belong to. Use each answer to make a better guess on the next row, and crack the code before the rows run out.

Levels

LevelPegsColoursRepeats in the codeGuessesPossible codes
Easy46No10360
Normal46Yes101,296
Hard58Yes1232,768

On Easy every colour appears at most once in the code, but your guesses may still repeat a colour, so a guess like 1 1 2 2 tests two colours at once.

How the answer is counted

Exact pegs are counted first: every hole where your colour matches the code. The partial count then looks only at the remaining holes, colour by colour, and takes the smaller of two numbers: how often the colour appears in the rest of your guess and how often in the rest of the code. Each peg of the code is used once, so repeated colours never score twice. Example: the code is Red, Red, Blue, Green and you guess Red, Blue, Red, Red. The first Red is exact. Of the rest, Blue scores one partial, and Red scores one partial because only one Red is left in the code. The answer is 1 exact and 2 partial.

Controls

  • Mouse: click a colour to drop it into the highlighted hole; the highlight then jumps to the next empty hole. Click a hole first to choose where the next colour goes, click the highlighted hole again (or right-click a hole) to empty it, or drag a colour straight onto any hole. Dragging a peg to another hole swaps the two, and dragging it off the row removes it. Clicking a peg in an earlier row copies its colour into the highlighted hole.
  • Keyboard: 1–6 (up to 8 on Hard) place a colour, ← and → move between holes, ↑ and ↓ change the colour of the selected hole, Backspace clears and steps back, Enter checks the row and F switches full screen.
  • Touch: tap a colour, tap a hole to select it, or drag a colour onto a hole. The palette sits right under the board, and the page does not scroll while you play.

Colour-blind-friendly pegs

Every colour carries its number, which is also its key: 1 Red, 2 Blue, 3 Yellow, 4 Green, 5 Orange, 6 Purple, 7 White and 8 Black. Turn on Symbols and each colour shows its own shape instead: triangle, square, star, diamond, plus, cross, heart and crescent. The answer uses shapes too, a filled dot and a ring, so the whole game can be played without telling colours apart.

Hints

Codes left shows how many codes still agree with every answer so far, and with a peg you revealed. A Normal game starts with 1,296 candidates; a good first guess often cuts that to a few hundred. When the counter reaches 1, only one code is left. With the counter on, each row also shows the count after that guess on wider screens. Turning it on or off is free.

Reveal a peg uncovers one random peg of the code. You can use it once per game; the first press asks for confirmation, and every reveal is recorded in your stats.

Strategy

  • On Normal, start with two colours twice each, such as 1 1 2 2. In 1976 Donald Knuth showed that this opening, followed by careful choices, solves every Normal code in at most five guesses.
  • Prefer a guess that splits the remaining codes into many small groups, even when it cannot be the answer itself.
  • An answer of zero is valuable: every colour in that guess can be crossed out.
  • The game refuses a guess you have already tried, so no row is wasted by accident.

Stats

For each level the game keeps games played, wins, win rate, average guesses per win, your best game, how many pegs you revealed and a chart of how many guesses your wins needed. A game counts as played after your first Check or reveal. Everything is stored only in your browser, and the Stats panel can reset it.

Frequently asked questions

Is every code solvable?

Yes. The code is picked at random from all codes allowed on the level, and with enough care every one of them can be found within the rows you have.

Sources

  • Knuth D E (1976). Journal of Recreational Mathematics, 9(1), 1–6. The proof that the opening 1 1 2 2 solves every code of four pegs and six colours in at most five guesses.