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} ans #{r.max}"
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
print "Guessing #{guess} \t"
turns += 1
turns += 1
low_high = secret <=> guess # -1, 0, or 1
low_high = secret <=> guess # -1, 0, or 1
msg = ["found the number in #{turns} turns","too low", "too high"][low_high]
puts ["found the number in #{turns} turns", "too low", "too high"][low_high]
puts "Guessing #{guess} \t #{msg}"
low_high
low_high
end
end