lib/codebreaker_diz/matcher.rb in codebreaker_diz-0.2.3 vs lib/codebreaker_diz/matcher.rb in codebreaker_diz-0.2.4
- old
+ new
@@ -3,11 +3,11 @@
require_relative 'config'
module CodebreakerDiz
class Matcher
def initialize(secret_code, user_code)
- @secret_code = secret_code
+ @secret_code = secret_code.clone
@user_code = user_code
@exact_matches = 0
@number_matches = 0
end
@@ -19,17 +19,17 @@
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
+ next unless @secret_code.include? user_code_number
+
+ if secret_code_number == user_code_number then @exact_matches += 1
+ elsif @secret_code.include? user_code_number then @number_matches += 1
end
- delta << user_code_number
+ @secret_code.delete_at(@secret_code.index(user_code_number))
end
end
end
end