require 'set' histo = Set.new [] a = [1,2,3,4] 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 n,m = torai(a) exit 0 if n == 4 k = n+m (100-24).times { if k == 4 break end b = neigh(a) while histo.include?(b) b = neigh(a) end n,m = torai(b) if (n+m) > k a = b k = n + m 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 }