Skip to content

Instantly share code, notes, and snippets.

@them0nk
Created April 26, 2012 01:59
Show Gist options
  • Save them0nk/2495177 to your computer and use it in GitHub Desktop.
Save them0nk/2495177 to your computer and use it in GitHub Desktop.
Given an array find the combination of two numbers in the array which makes the given sum
require 'set'
def twosum arr,sum_arr
a = Set.new(arr)
sum_arr.each do |sum|
count = 0
arr.each do |elem|
puts("#{sum} = #{elem} + #{sum-elem}") if a.include? (sum-elem)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment