require_relative './guess_result'

class CombinationLock
  def initialize(code)
    @code = code
  end

  def check_guess(guess)

    guess.values.each_with_index.reduce(GuessResult.new) do |memo, (digit, index)|
      if digit == code[index]
        GuessResult.new(cows: memo.cows, bulls: memo.bulls+1)
      elsif code.include?(digit)
        GuessResult.new(cows: memo.cows+1 , bulls: memo.bulls )
      else
        memo
      end

    end

  end

  private
  attr_reader :code

end
