Skip to content

Instantly share code, notes, and snippets.

@toshihirock
Last active February 15, 2016 23:56
Show Gist options
  • Save toshihirock/2201233fa068e3f9b752 to your computer and use it in GitHub Desktop.
Save toshihirock/2201233fa068e3f9b752 to your computer and use it in GitHub Desktop.
def get(array, target)
i = 0
j = i + 1
while i < array.length - 1 do
while j < array.length do
sum = array[i] + array[j]
return "index1 = #{i} , index2 = #{j}" if sum == target
j += 1
end
puts "-------"
i += 1
j = i + 1
end
"none"
end
# main
array = [5, 2, 0, 9, 6, 1, 3, 4]
target = 9
puts get(array, target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment