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:
secret = rand(r)
turns = 0
 
puts "Guess a number between #{r.min} ansand #{r.max}"
r.bsearch do |guess| # bsearch works on ranges
putsprint "Guessing #{guess} \t #{msg}"
turns += 1
low_high = secret <=> guess # -1, 0, or 1
msg =puts ["found the number in #{turns} turns", "too low", "too high"][low_high]
puts "Guessing #{guess} \t #{msg}"
low_high
end