require 'set' histo = Set.new [] def torai(a) puts a*' ' STDOUT.flush gets.split.map(&:to_i) end def neigh(a) cs = (0..9).select{|i| not a.include?(i) }.to_a a[rand(4)] = cs[rand(cs.size)] return a end a = [0,1,2,3] n,m = torai(a) exit 0 if n == 4 k = n+m for i in 0..4 do for x in 0..9 do if not a.include?(x) b = a.clone b[i] = x n,m = torai(b) if (n+m) == 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]*' ' n,m=gets.split.map(&:to_i) if n==4 exit 0 end }