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
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15028 Solvers
-
Find the alphabetic word product
3074 Solvers
-
1666 Solvers
-
Flag largest magnitude swings as they occur
659 Solvers
-
1553 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!