Created
July 11, 2015 08:57
-
-
Save jweinst1/3aa843415cd5f7649578 to your computer and use it in GitHub Desktop.
Shortening Search Algorithm.py
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 Shortening_search(target): | |
assert 0<target<1000 #must be between 1 and 999. | |
list, count = range(1000), 0 | |
while len(list) > 1: | |
if list[0] == target: | |
return count | |
elif list[-1] == target: | |
return count | |
else: | |
list.pop() | |
list.remove(list[0]) | |
count += 1 | |
return count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment