# frozen_string_literal: true # Write a function which, given an array of integers of value greater or equal to 0, returns all unique pairs which # sum to 100. # # Example data: # # input = [0, 1, 100, 99, 0, 10, 90, 30, 55, 33, 55, 75, 50, 51, 49, 50, 51, 49, 51] # output = [[1,99], [0,100], [10,90], [51,49], [50,50]] class UniquePair def self.unique_pairs(numbers, sum=100) Array(numbers) .combination(2) .map do |x, y| x, y = y, x if x > y [x, y] if x + y == sum end.compact.sort.uniq || [] end end