summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2009-05-28 13:07:10 -0600
committermo khan <mo@mokhan.ca>2009-05-28 13:07:10 -0600
commite1afbc888054063cb471affdd2b0ff02f423b8ef (patch)
tree3a3840637e88992740bd132342deaa910c0259eb /lib
parent1b3e97664a6fe0af00cb0aef406ebba8de69f7c9 (diff)
made it up to page 88main
Diffstat (limited to 'lib')
-rw-r--r--lib/mastermind/game.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/mastermind/game.rb b/lib/mastermind/game.rb
index 4485b58..1ed91a2 100644
--- a/lib/mastermind/game.rb
+++ b/lib/mastermind/game.rb
@@ -10,15 +10,15 @@ module Mastermind
@messenger.puts "Enter guess:"
end
def guess(guess)
- result = []
+ result = [nil,nil,nil,nil]
guess.each_with_index do |peg, index|
if @code[index] == peg
- result << "b"
+ result[index] = "b"
elsif @code.include?(peg)
- result << "w"
+ result[@code.index(peg)] ||= "w"
end
end
- @messenger.puts result.sort.join
+ @messenger.puts result.compact.sort.join
end
end
end