Created
April 21, 2010 17:14
-
-
Save cypok/374116 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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