Sha256: 2dee3bb5b6bd2c038f957a459b2afcec51176c258beb78946ae0eb1142ab581f
Contents?: true
Size: 787 Bytes
Versions: 2
Compression:
Stored size: 787 Bytes
Contents
# frozen_string_literal: true require_relative 'config' module CodebreakerDiz class Matcher def initialize(secret_code, user_code) @secret_code = secret_code @user_code = user_code @exact_matches = 0 @number_matches = 0 end def matches calculate_matches EXACT_MATCH_SIGN * @exact_matches << NUMBER_MATCH_SIGN * @number_matches end private def calculate_matches delta = [] @secret_code.zip(@user_code).each do |secret_code_number, user_code_number| if secret_code_number == user_code_number then @exact_matches += 1 elsif (@secret_code - delta).include? user_code_number then @number_matches += 1 end delta << user_code_number end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
codebreaker_diz-0.2.3 | lib/codebreaker_diz/matcher.rb |
codebreaker_diz-0.2.2 | lib/codebreaker_diz/matcher.rb |