Problem 43562. Mastermind
Solution Stats
Problem Comments
-
2 Comments
If the hidden code is [2 4 4 2] and the attempt is [1 2 3 5], then the test gives rightNumRightPlace = 0, rightNumWrongPlace = 2. I my head, rightNumWrongPlace should be 1. Have I misunderstood? .
I rate difficult-level this challenge because in your test case is not working correctly. Sometimes you pass [3right place 1wrong place] which is not possible. You should replace the way you calculate the RightNumWrongPlace.
This may fix things (it's also vectorized)
function [r w]=tellMe(sol, gues)
% this function calculates the score of the pegs given a solution
1x4 and a matrix of guesses nx4.
r = sum( sol==gues,2);
s = size(gues,1);
rows = repmat( (1:s)',1,4);
w = sum(min( accumarray(sol',1,[6 1])', accumarray( [rows(:) gues(:)],1,[s 6])),2)-r;
end
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
Remove any row in which a NaN appears
8215 Solvers
-
2179 Solvers
-
Program an exclusive OR operation with logical operators
698 Solvers
-
Project Euler: Problem 7, Nth prime
1301 Solvers
-
Create a vector whose elements depend on the previous element
577 Solvers
More from this Author25
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!