Skip to content

Instantly share code, notes, and snippets.

@jgarlick
Created July 20, 2012 20:00
Show Gist options
  • Save jgarlick/3152886 to your computer and use it in GitHub Desktop.
Save jgarlick/3152886 to your computer and use it in GitHub Desktop.
def find_pair(array, value)
lookup = {}
array.each_with_index do |i, index|
if i < value
search = value - i
i2 = lookup[search]
if i2 then return [i2, i] else lookup[i] = index end
end
end
return nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment