def two_sum(nums, tg) b = [] nums.sort.combination(2){|x| b << x} c = b.reject{|x| x.sum != tg}[0] [nums.index(c[0]), nums.index(c[1])] end