# frozen_string_literal: true module Codebreaker class Core GUESSED_PLACE = '+' GUESSED_PRESENCE = '-' CB_ARRAY_SIZE = 4 GAME_NUMBER_RANGE = (1..6).freeze def generate_secret_code CB_ARRAY_SIZE.times.map { rand(GAME_NUMBER_RANGE) } end def check(cb_numbers, guess_arr) result = '' code_guess_arr = cb_numbers.zip(guess_arr) code_after_each = [] guess_after_each = [] code_guess_arr.each do |unite_arr| if unite_arr.uniq.size == 1 result += GUESSED_PLACE else code_after_each << unite_arr.first guess_after_each << unite_arr.last end end guess_after_each.each { |elem| result += GUESSED_PRESENCE if code_after_each.uniq.include?(elem) } result end end end