Skip to content

Instantly share code, notes, and snippets.

@camilopayan
Created September 29, 2011 02:28
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 camilopayan/1249841 to your computer and use it in GitHub Desktop.
Save camilopayan/1249841 to your computer and use it in GitHub Desktop.
Number2 code
def find_mystery(length, mystery):
boxes = range(1, length+1)
step = int(sqrt(length))
count = 0
for t in range(0, length+1, step):
count = count+1
if t >= length:
print "Now checking %d and that is outta range" % t
else:
print "Now checking %d and that is %d" % (t, boxes[t])
if t >= length or boxes[t] > mystery:
u = t-step
for x in boxes[u:]:
print "Now checking %d" % x
count = count+1
if x == mystery:
print "%d guesses" % count
return x
elif boxes[t] == mystery:
print "%d guesses" % count
return boxes[t]
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment