M = 100000 M = 20 def get(x, y) x = [M, [0, x].max].min y = [M, [0, y].max].min puts "#{x} #{y}" STDOUT.flush d = gets.to_i return d end y = M / 2 left = 0 right = M while right - left > 2 x1 = (left + left + right) / 3 x2 = (left + right + right) / 3 d1 = get(x1, y) d2 = get(x2, y) if d1 < d2 right = x2 else left = x1 end end mn_d = M * M mn_x = left ((left - 5)..(left + 5)).each do |x| d = get(x, y) if d < mn_d mn_d = d mn_x = x end end get(mn_x, y + mn_d) get(mn_x, y - mn_d)