I am trying to solve this code cracking problem. The solution is either the code or all possible solutions if you can't narrow the possibilities.

We have a 5 character code that is consisting of digits {0,1, ..., 7}. We have 10 attempts and for each attempt we have the amount of correctly guessed digits on the right indexes, and the number of correctly guessed digits on an incorrect index.

What I did what to generate all 5 digit numbers consisting of digits {0,1, ..., 7}., however I failed to find any way to narrow the attempts down. Could you help me find the right algorithm? Thanks!

  • $\begingroup$ Please clarify "the number of correctly guessed digits on an incorrect index". Suppose the code is 11222 and the guess is 22333. What is that number? $\endgroup$
    – John L.
    May 29, 2019 at 19:23
  • $\begingroup$ @Apass.Jack The number is 2. $\endgroup$
    – james F.
    May 29, 2019 at 20:00

1 Answer 1


Your problem is a variant of Mastermind. In particular, it is "Super Mastermind". Wikipedia contains some relevant pointers, and you can find many more by searching for Super Mastermind. For example, Temporel and Kovacs describes a heuristic algorithm that solves Super Mastermind using roughly 5–7 guesses. The same work also contains pointers to other algorithms.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.