numbers = Array.new(10, 0) def query(x) STDOUT.puts(x) STDOUT.flush res = gets.chomp.split [res[0].to_i, res[1]] end 10.times do |i| max_v = 0 num = -1 10.times do |n| numbers[i] = n v, status = query(numbers.join) if status == 'unlocked' exit end if max_v < v max_v = v num = n end end numbers[i] = num end