Problem 44248. Mastermind V: Optimal Solver - average number of guesses
The following description contains a copy of Richard Zapor's Mastermind IV: Optimal Solver - max of 5 guesses
Mastermind is a code breaking logic puzzle. A pattern of 6 colors(values 1:6) of four positions (1111;1112;....6666) for a possible 6^4(1296) cases is generated. The solver plays a length 4 vector with values 1:6. Accuracy of the play is returned by a count of values in the right position and a count of values(excluding those in the right positions) common to the solution.
Answer:1233 Guess:3231 Response: 2,2 as x23x are right value/position, 3xx1 are right values.
[guess]=solve_mastermind(mguess,mpegs,m,mpc,mc,mpc5c,v)
where guess is a 1x4 vector, mguess is the kx4 matrix of prior guesses and is empty on first try, mpegs is kx2 giving right [value/position, values] for mguess, m is a 1296x4 array [1 1 1 1;...6 6 6 6] of all solutions, mpc is a 1296x1296 array of 0:4 for value/position solutions, mc is a 1296x1296 array of 0:4 for value solutions, mpc5c is state array of a combined mpc and pc of values 0:20, 5*mpc+mc, and v is integer value of solutions 1111 thru 6666. will be provided.
Scoring: the average number of guesses of all 1296 cases.
See Also:
Mastermind I: Solve all 1296 cases
Solution Stats
Problem Comments
-
14 Comments
@yurenchu, ismember/ismembc2 perform a binary search in runtime complexity O(logn), faster than a linear search with runtime complexity O(n).
https://www.mathworks.com/matlabcentral/answers/92533-how-do-i-perform-a-binary-search-of-a-presorted-array
I wasn't aware of stuff like that. Thanks for the interesting information and weblink, it's indeed helpful. However, it seems that 7300 game iterations doesn't offer much space to implement experimentative/lengthier/more extensive algorithms (such as ones considering ps(k,:) instead of ps(k,k) as the search space for the next best guess), without hitting Cody's time limit. (At least not to a person like me who doesn't know which built-in MATLAB functions work fast and which work "slowly".) But anyway, still very interesting problem/challenge.
@yurenchu. Let's take this as an additional challenge :-)
Solution Comments
Show commentsGroup

Board Games II
- 14 Problems
- 10 Finishers
- Find the Next Legal Move in Reversi
- Determine the Result of a Move in Reversi
- Mastermind
- Mastermind I: Solve all 1296 cases
- Mastermind II: Solve in 8 or less
- Mastermind III: Solve in 1
- Mastermind IV: Optimal Solver - max of 5 guesses
- Mastermind V: Optimal Solver - average number of guesses
- Rumis Scorer 1
- Rumis Scorer 2
- Rumis Scorer 3
- Rumis Scorer 4
- Connect Four: find winning move
- Connect 4 (the boardgame)
Problem Recent Solvers12
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!