Skip to content

Instantly share code, notes, and snippets.

@coreyjs
Created February 25, 2019 18:53
Show Gist options
  • Select an option

  • Save coreyjs/6e37f4c89760cefde2cb192b0c424058 to your computer and use it in GitHub Desktop.

Select an option

Save coreyjs/6e37f4c89760cefde2cb192b0c424058 to your computer and use it in GitHub Desktop.
Daily Coding Email Challenge 2
puts 'Daily Coding Challenge 1'
puts 'Given a list of numbers and a number k, return whether any two numbers from the list add up to k.'
input = [10, 15, 3, 7]
k = 17
puts "input = #{input.to_s}"
puts "k = #{k}"
input.each_with_index do |num, i|
# remainder is the number we want to find exists in the array
remainder = k - num
if input.include?(remainder) and input.index(remainder) != i
puts 'Found Answer: '
puts "#{num} (index #{i}) + #{remainder} (index #{input.index(remainder)}) == #{k}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment