Skip to content

Instantly share code, notes, and snippets.

@majiang
Created May 5, 2012 19:12
Show Gist options
  • Save majiang/2604827 to your computer and use it in GitHub Desktop.
Save majiang/2604827 to your computer and use it in GitHub Desktop.
unbinary search
def bs(a, b):
if a == b:
return a
if f(a) < 0:
return bs((a+b) / 2, b)
if f(b) > 0:
return bs(a, (a+b) / 2)
raise ValueError('something wrong :(')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment