answer = [] (0..9).to_a.combination(4){|_v| _v.permutation{|v| answer << v } } def simulate(answer,query) x=y=0 4.times{|i| if answer[i] == query[i] x+=1 elsif answer.include?(query[i]) y+=1 end } return [x,y] end def send(v) puts v*" " ; STDOUT.flush return gets.split.map(&:to_i) end while answer.size > 1 v = answer.sample res = send(v) exit 0 if res == [4,0] answer.delete_if{|e| simulate(e,v) != res} end abort if answer.size == 0 puts answer[0]*" " ; STDOUT.flush