Created
September 29, 2011 02:28
-
-
Save camilopayan/1249841 to your computer and use it in GitHub Desktop.
Number2 code
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 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