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
-
36930 Solvers
-
1332 Solvers
-
given 3 sides, find area of this triangle
777 Solvers
-
Project Euler: Problem 8, Find largest product in a large string of numbers
964 Solvers
-
51 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!