# frozen_string_literal: true left = 1 right = 10**9 loop do if left == right puts %(! #{left}) STDOUT.flush exit end center = (left + right) / 2 + 1 puts %(? #{center}) STDOUT.flush gets.chomp == '1' ? (left = center) : (right = center - 1) end