Created
August 4, 2016 15:10
-
-
Save holsted/f4ee0c1e8ce095b23563d94ef1a724b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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