Created
March 3, 2009 04:06
-
-
Save nevernormal1/73169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use a covering technique to cover first blacks, then whites | |
# At each step, anything covered is acccounted for. | |
# Anything uncovered at the end is just plain wrong | |
def guess(guess) | |
covered_result = @secret_code.dup | |
guess.each_with_index do |color, i| | |
covered_result[i] = 'b' if @secret_code[i] == color | |
end | |
guess.each_with_index do |color, i| | |
match = covered_result.index(color) | |
covered_result[match] = 'w' if match | |
end | |
print_result(covered_result) | |
end | |
private | |
def print_result(result) | |
@messenger.puts result.select {|c| c =~ /[bw]/}.sort.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment