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 while answer.size > 1 v = answer.sample puts v*" " ; STDOUT.flush res = gets.split.map(&:to_i) answer.delete_if{|e| simulate(e,v) != res} end