Last active
March 4, 2017 17:47
-
-
Save CamDavidsonPilon/ef1f6e8db40cf00156d8afdadf697d7e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 mod_binary_search(round, previous_winner, dataset): | |
# round starts at 0, previous_winner starts at 0 | |
if 2**round >= len(dataset): | |
return previous_winner | |
mod = 2 ** (round + 1) | |
if test(dataset, previous_winner, mod): | |
return mod_binary_search(round+1, previous_winner, dataset) | |
else: | |
return mod_binary_search(round+1, previous_winner + 2**round, dataset) | |
def test(dataset, target, modulus): | |
filtered_dataset = filter(lambda x: x % modulus == target, dataset) | |
if _test(filtered_dataset): | |
return True | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment