Skip to content

Instantly share code, notes, and snippets.

@jredville
Created April 18, 2010 06:42
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 jredville/370048 to your computer and use it in GitHub Desktop.
Save jredville/370048 to your computer and use it in GitHub Desktop.
def search(arr, t)
min = 0
max = arr.count -1
mid = (max-min)/2
if arr.count == 0 || (arr.count == 1 && arr[0] != t)
return -1
elsif t <= arr[mid]
return search(arr[0..mid], t)
else
return mid + search(arr[mid..-1], t)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment