Skip to content

Instantly share code, notes, and snippets.

@philosodad
Created December 19, 2011 05:41
Show Gist options
  • Save philosodad/1495566 to your computer and use it in GitHub Desktop.
Save philosodad/1495566 to your computer and use it in GitHub Desktop.
Learn How You Fail
def binary_search search_array, key
if search_array[search_array.length/2] == key then return search_array.length/2 end
if search_array[search_array.length/2] < key then binary_search (search_array(search_array.length/2...search_array.length), key) end
if search_array[search_array.length/2] > key then binary_search(search_array(0..search_array.length/2), key) end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment