I was watching the Mastermind Solution Video (part.2) and discovered that the solution for num_near_matches is incorrect, even though it passes the rspec tests, as written.

(I looked back at the given solution and rspec tests for the Mastermind provided in the Alpha course, and they do not have this issue. This is just for the new Mastermind project in the Foundations course.)

def num_near_matches(guess_code)

_count = 0

_(0…guess_code.length).each do |i|

__if guess_code[i] != self[i] && self.pegs.include?(guess_code[i])

___count += 1

__end

_end

_count

end

if self.pegs = [“R”, “G”, “B”, “Y”] and guess_code = [“R”, “R”, “R”, “R”]

it returns ---- exact: 1, near: 3

it should return ---- exact: 1, near: 0

because the only “R” is accounted for in exact

**another example**

if self.pegs = [“R”, “G”, “B”, “B”] and guess_code = [“Y”, “R”, “R”, “R”]

it returns ---- exact: 0, near: 3

it should return ---- exact: 0, near: 1

because there is only one “R” in the solution, and it’s not in the exact position

**final example**

if self.pegs = [“R”, “G”, “B”, “Y”] and guess_code == [“Y”, “Y”, “R”, “R”]

it returns ---- exact: 0, near: 4

it should return ---- exact: 0, near: 2

near of 4 implies that the pegs solution is [“R”, “R”, “Y”, “Y”]. Both guess Y’s and both guess R’s would get counted, but the total number of each respectively is only 1, or 2 total.

The rspec test cases are written in just such a way that they omit a scenario where the guess has more pegs of a certain color than the solution.