$stdout.sync = true ns = *0..9 ns.first(8).combination(4) do |a| puts a.join(" ") x, y = gets.split.map(&:to_i) exit if x == 4 && y == 0 begin ns -= a; break end if x == 0 && y == 0 end ns.combination(4) do |a| puts a.join(" ") x, y = gets.split.map(&:to_i) exit if x == 4 && y == 0 if x + y == 4 then a.permutation do |a| puts a.join(" ") x, y = gets.split.map(&:to_i) exit if x == 4 && y == 0 end end end