fst = 0 [2, 4, 6, 8].each do |i| puts "0 1 #{i} #{i + 1}" fst += gets.chomp.split(' ').map(&:to_i).reduce(:+) end if fst == 4 sets = [[2, 3], [4, 5], [6, 7], [8, 9]] elsif fst == 7 sets = [[0, 1], [2, 3], [4, 5], [6, 7]] elsif fst == 10 sets = [[0, 0], [1, 1], [2, 3], [6, 7]] end nums = [] 4.times do |i| inp = [sets[0][0], sets[1][0], sets[2][0], sets[3][0]] puts inp.join(' ') fb1 = gets.chomp.split(' ').map(&:to_i).reduce(:+) inp[i] = sets[i][1] puts inp.join(' ') fb2 = gets.chomp.split(' ').map(&:to_i).reduce(:+) if fb2 >= fb1 nums.push(sets[i][1]) else nums.push(sets[i][0]) end end nums.permutation(4).each do |_arr| puts nums.join(' ') ans = gets.chomp.split(' ').map(&:to_i) break if ans == [4, 0] end