Skip to content

Instantly share code, notes, and snippets.

@ghewgill
Created April 10, 2014 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghewgill/10421051 to your computer and use it in GitHub Desktop.
Save ghewgill/10421051 to your computer and use it in GitHub Desktop.
import collections
import random
MAX = 2**64
def search(weight, target):
low = 0
high = MAX
time = 0
while True:
x = low + (high - low) // weight
if x < target:
time += 1
low = x + 1
elif x > target:
time += 300
high = x - 1
else:
return time
for w in range(2, 500):
a = [search(w, random.randint(0, MAX)) for _ in range(1000)]
print "%d,%d" % (w, sum(a) / len(a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment