Created
April 26, 2012 01:59
-
-
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
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
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