c = 0 loop { puts "? 0" STDOUT.flush ans = gets.to_i c += 1 if ans == 0 puts "! #{c}" STDOUT.flush break end }