Created
May 5, 2012 19:12
-
-
Save majiang/2604827 to your computer and use it in GitHub Desktop.
unbinary search
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 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