Skip to content

Instantly share code, notes, and snippets.

@aokolish
Created August 8, 2012 03:36
Show Gist options
  • Save aokolish/3291828 to your computer and use it in GitHub Desktop.
Save aokolish/3291828 to your computer and use it in GitHub Desktop.
require 'pry'
class SearchLoopingTwo
def self.chop(query, col)
left = 0
right = col.count - 1
middle = col.count / 2
#binding.pry if query == 5
while right >= left do
if query > col[middle]
left = middle + 1
middle = (right - middle) / 2
elsif query < col[middle]
right = middle - 1
middle = (middle - left) / 2
else
return middle
end
end
-1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment