Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This tracks wheather to subtract or add
- tralse = True
- #This is the amount of steps we take
- ptr = 1
- #This is what I want the cow to find
- goal = 1000
- #This is the current locaiton of the "cow"
- location = 0
- #This counts the total Steps
- steps = 0
- # This tells me whether to subtract or not
- flag = False
- #Go until we reach the goal
- while True:
- #Check wheather to subtract or add
- if tralse:
- #Subtract until we get to correct place to trun around and go the other way
- for i in range(ptr):
- #Add to location (to the right)
- location += 1
- #Increment the steps counter
- steps += 1
- #Check if we've reached the goal yet
- if goal == location:
- #show the steps
- print(steps)
- #Break out
- flag = True
- break
- #This is the same thing as above exept for subtracting
- else:
- for i in range(ptr):
- steps += 1
- location -= 1
- if goal == location:
- print(steps)
- flag = True
- break
- if flag == True:
- break
- tralse = not tralse
- ptr *= 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement