def ternary_search_tree(left, right) loop_cnt = 24 loop_cnt.times do if yield((left * 2 + right) / 3) < yield((left + right * 2) / 3) right = (left + right * 2) / 3 else left = (left * 2 + right) / 3 end end (left + right) / 2 end cy = 0 cx = 0 STDOUT.puts("%d %d" % [cx, cy]) STDOUT.flush current_d = gets.to_i if current_d == 0 exit end cx = ternary_search_tree(0, 100_001) { |x| STDOUT.puts("%d %d" % [x, cy]) STDOUT.flush d = gets.to_i if d == 0 exit end d } cy = ternary_search_tree(0, 100_001) { |y| STDOUT.puts("%d %d" % [cx, y]) STDOUT.flush d = gets.to_i if d == 0 exit end d }