def ask a $stdout.puts a.join(' ') $stdout.flush x,y = gets.split.map(&:to_i) exit 0 if x == 4 [x,y] end a = nil [*0...10].combination(4).to_a.shuffle.each { |c| x,y = ask c if x == 0 && y == 0 a = c break end } 4.times { |i| x = nil 10.times { |j| next if a.include? j a[i] = j x,y = ask a if x == i+1 break end } }