Class: CodebreakerDiz::Matcher
- Inherits:
-
Object
- Object
- CodebreakerDiz::Matcher
- Defined in:
- lib/codebreaker_diz/matcher.rb
Class Method Summary collapse
Class Method Details
.calculate_matches(secret, user_code) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/codebreaker_diz/matcher.rb', line 8 def calculate_matches(secret, user_code) delta = [] result = [] (0...CODE_LENGTH).each do |i| if secret[i] == user_code[i] then result << EXACT_MATCH_SIGN elsif (secret - delta).include? user_code[i] then result << NUMBER_MATCH_SIGN end delta << user_code[i] end result.sort!.join end |