class Codebreaker::Entities::Processor

Constants

MATCHED_DIGIT_CHAR
UNMATCHED_DIGIT_CHAR

Attributes

code[R]
guess[R]
result[R]

Public Instance Methods

secret_code_proc(code, guess) click to toggle source
# File lib/codebreaker/entities/processor.rb, line 11
def secret_code_proc(code, guess)
  @code = code.split('')
  @guess = guess.split('')
  handle_matched_digits.join + handle_matched_digits_with_wrong_position.join
end

Private Instance Methods

handle_matched_digits() click to toggle source
# File lib/codebreaker/entities/processor.rb, line 19
def handle_matched_digits
  code.map.with_index do |_, index|
    next unless code[index] == guess[index]

    @guess[index], @code[index] = nil
    MATCHED_DIGIT_CHAR
  end
end
handle_matched_digits_with_wrong_position() click to toggle source
# File lib/codebreaker/entities/processor.rb, line 28
def handle_matched_digits_with_wrong_position
  guess.compact.map do |number|
    next unless @code.include?(number)

    @code.delete_at(code.index(number))
    UNMATCHED_DIGIT_CHAR
  end
end