def query(q) puts q*" ";STDOUT.flush x,y=gets.split(" ").map(&:to_i) exit if x==4 return [x,y] end ng=[] mem=[] ymax=0 (0..9).to_a.combination(4){|ce| next if ng.inject(false){|s,e|s=s||ce.include?(e)} flg=false mem.each{|e| flg =flg|| (ce&e).size < ymax # 一致数 } next if flg ce.permutation(4){|pe| x,y=query(pe) if pe==ce if y==0 ce.each{|e| ng.push(e)} elsif y>ymax ymax=y mem.clear mem.push(ce) else mem.push(ce) end break if y!=4 end } } puts "fin"