Skip to content

Commit

Permalink
pass for a number match duplicated in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eben Geer committed Mar 7, 2012
1 parent 4e63e20 commit d867843
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions codebreaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ def start(secret)

def guess(guess)
mark = ''
(0..3).each do |i|
if guess[i] == @secret[i]
secret = @secret
i = 0
while i < guess.length do
if guess[i] == secret[i]
mark.insert(0, '+')
guess[i] = ' '
elsif guess.include?(@secret[i])
guess[i] = ''
secret[i] = ''
else
i += 1
end
end

secret.each_char do |c|
if guess.include? c
mark << '-'
guess[guess.index(c)] = ''
end
end
@output.puts mark
Expand Down

0 comments on commit d867843

Please sign in to comment.