Play in your browser · Logic
Code breaker
Crack a secret code of four colours from six in ten guesses or fewer. After every guess you see how many colours are in the right place and how many are right but in the wrong place.
This game runs in your browser with JavaScript. Turn it on to play, or get Omni Brain for the full version.
How to play
- Press Start. A secret code of four pegs is hidden; each peg is one of six colours, and colours can repeat.
- Tap colours, or press 1–6, to fill the four positions, then press Check. Tap a peg in the current row, or press Backspace, to change it.
- After each guess, ● shows how many pegs are the right colour in the right place and ○ how many are the right colour in the wrong place. Crack the code within ten guesses.
What your score means
Your result is the number of guesses you needed, so lower is better. With four positions and six colours there are 1,296 possible codes, yet Donald Knuth showed in the 1970s that a careful strategy always finds the code in five guesses or fewer.
So five or fewer is excellent play, and every guess beyond that is room to sharpen your method. A lucky first or second guess happens now and then; over several games your typical number tells you more than a single best. Your best result is kept in this browser.
About Mastermind
Mastermind is a code-breaking board game invented by Mordecai Meirowitz around 1970. One player hides a code of coloured pegs, and the other tries to find it, with a hint after each guess: how many pegs are the right colour in the right place, and how many are the right colour in the wrong place. Each hint rules out many possible codes, so the game is an exercise in deduction and hypothesis testing: you form an idea of what the code might be, choose a guess that tests it, and update your picture from the answer. Keeping several clues in mind at once leans on working memory as well. This browser version uses the classic size, four pegs from six colours, and every colour carries a number, so the game never depends on telling colours apart. In Omni Brain the same idea runs as Code, with difficulty that adapts to you: later codes are longer, with more colours and repeats.
Techniques from the app
- Change one thing. Alter a single position between guesses. Then the change in the hint tells you exactly what that position did.
- Use the zero. A guess with no hits is the most useful one: every colour in it is out. Try to get one early.
Train deduction every day in Omni Brain
Code and many more short games, each with a technique you can use outside the app. Free every day.
Questions about Mastermind
How do you play Mastermind?
A secret code of four coloured pegs is hidden. You guess a code, and the hint tells you how many pegs are the right colour in the right place (●) and how many are the right colour in the wrong place (○). Use the hints to narrow the code down before your ten guesses run out.
What is a good first guess in Mastermind?
A guess with two pairs, such as 1 1 2 2, is a classic opening: it tests two colours at once, and the hint tells them apart well. Knuth's five-guess strategy starts with exactly this pattern.
How many guesses does Mastermind need?
With four pegs and six colours there are 1,296 possible codes. Knuth showed that a careful strategy can always crack the code in five guesses or fewer, so ten guesses leave plenty of room to learn.
Why do the colours have numbers?
So the game works for everyone, including people who find some colours hard to tell apart: every colour carries its own number from 1 to 6, and the hints use filled and open dots with counts. On a keyboard you can type the numbers directly.
More games to try
Tower of Hanoi
Move the tower peg by peg, never a bigger disc on a smaller one, in as few moves as you can.
LogicPipes puzzle
Rotate the tiles until every pipe joins one network, with no open ends.
LogicAbstract reasoning test
Ten matrix puzzles from easy to hard: find the piece that completes each grid.