require 'set' histo = Set.new [] def torai(a) puts a*' ' STDOUT.flush gets.split.map(&:to_i) end a = [0,1,2,3] n,m = torai(a) exit 0 if n == 4 k = n+m for i in 0..3 do for x in 0..9 do if not a.include?(x) b = a.clone b[i] = x n,m = torai(b) if n==4 exit 0 end if k < (n+m) k = n+m a = b break end if k > (n+m) break end end end end a.permutation(4) {|a,b,c,d| puts [a,b,c,d]*' ' STDOUT.flush n,m=gets.split.map(&:to_i) if n==4 exit 0 end }