Skip to content

Instantly share code, notes, and snippets.

@cypok
Created April 21, 2010 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cypok/374116 to your computer and use it in GitHub Desktop.
Save cypok/374116 to your computer and use it in GitHub Desktop.
def find(arr, value)
l = 0
r = arr.size - 1
loop do
return nil if l == r and arr[l] != value
m = (l+r)/2
if arr[m] < value
l = m+1
elsif arr[m] > value
r = m-1
else
return m
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment