def trisearch(left, right, equal = nil, &block) 30.times { l = right - (2 * right - 2 * left) / 3 r = right - (right - left) / 3 lval = block.call(l) rval = block.call(r) if (lval <= rval) right = r else left = l end return left if (left == right) } best = block.call(left); bestidx = left; (left+1).upto(right){|t| f = block.call(t) if best > f best = f; bestidx = t end } return nil if equal && equal != block.call(bestidx) return bestidx end def query(x,y,z) puts "? #{x} #{y} #{z}" $>.flush dist = gets.to_i end def bye(x,y,z) puts "! #{x} #{y} #{z}" exit end x = y = z = 0 x = trisearch(-150,150){|t| query(t,y,z)} y = trisearch(-150,150){|t| query(x,t,z)} z = trisearch(-150,150){|t| query(x,y,t)} bye(x,y,z)