Skip to content

Instantly share code, notes, and snippets.

@btc
Created October 24, 2013 01:01
Show Gist options
  • Save btc/7129543 to your computer and use it in GitHub Desktop.
Save btc/7129543 to your computer and use it in GitHub Desktop.
require 'set'
def pairs arr, n
pairs = Set.new
arr.each_with_index do |left, i|
arr.each_with_index do |right, j|
if left + right == n and i != j
pair = [left, right].sort
if !pairs.include? pair
pairs << pair
end
end
end
end
return pairs
end
p = pairs([1, 23, 55, 40, 45, 99, 99, 45, 50], 100)
puts p.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment