Guess the number/With feedback (player): Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: Got rid of one variable and a typo) |
|||
Line 1,831: | Line 1,831: | ||
secret = rand(r) |
secret = rand(r) |
||
turns = 0 |
turns = 0 |
||
puts "Guess a number between #{r.min} |
puts "Guess a number between #{r.min} and #{r.max}" |
||
r.bsearch do |guess| # bsearch works on ranges |
r.bsearch do |guess| # bsearch works on ranges |
||
⚫ | |||
turns += 1 |
turns += 1 |
||
low_high = secret <=> guess # -1, 0, or 1 |
low_high = secret <=> guess # -1, 0, or 1 |
||
puts ["found the number in #{turns} turns", "too low", "too high"][low_high] |
|||
⚫ | |||
low_high |
low_high |
||
end |
end |