Skip to content

Instantly share code, notes, and snippets.

@asccigcc
Created March 24, 2018 14:14
Show Gist options
  • Save asccigcc/6e697bdcdbbb5f512ae92b32796afd93 to your computer and use it in GitHub Desktop.
Save asccigcc/6e697bdcdbbb5f512ae92b32796afd93 to your computer and use it in GitHub Desktop.
Find the sum into a sequence
# Create a funtion that shows the pair of numbers that return the same results
# as expected. In the next format find_sums([1,2,3,4,5,6]. 12)
def find_sum(list, expected_result)
list_index = []
hash_list = {}
list.each_with_index {|value, key| hash_list[key] = value }
hash_list.each do |item|
seed = item
hash_list.each do |item|
if seed.first != item.first && seed.last + item.last == 12
list_index << "#{seed.first} and #{item.first} (#{seed.last} + #{item.last} = 12)"
end
end
end
list_index
end
result = find_sum([1,3,5,4,7,9],12)
result.each{ |item| puts item }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment