Skip to content

Instantly share code, notes, and snippets.

@holsted
Created August 4, 2016 15:10
Show Gist options
  • Save holsted/f4ee0c1e8ce095b23563d94ef1a724b5 to your computer and use it in GitHub Desktop.
Save holsted/f4ee0c1e8ce095b23563d94ef1a724b5 to your computer and use it in GitHub Desktop.
sample_input = [0, 1, 100, 99, 0, 10, 90, 30, 55, 33, 55, 75, 50, 51, 49, 50, 51, 49, 51];
def unique_pairs(array)
pairs = []
array.combination(2).map do | pair |
if pair[0] + pair[1] === 100 && !pairs.include?(pair) && !pairs.include?(pair.reverse())
pairs << pair
end
end
p pairs
end
unique_pairs(sample_input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment