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