def query(q) puts q*" ";STDOUT.flush x,y=gets.split(" ").map(&:to_i) exit if x==4 return [x,y] end c=0 (0..9).to_a.combination(4){|ce| ce.permutation(4){|pe| x,y=query(pe) break if y!=4 } }