min_x = 0 max_x = 10**9 correct = false while !correct x = (max_x - min_x) / 2 + min_x print "? #{x}\n" STDOUT.flush y = gets.strip.split(' ')[1].to_i if x == y break elsif y == 1 max_x = (max_x - min_x) / 2 + min_x else min_x = (max_x - min_x) / 2 + min_x end end