Advertisement
SoggyCrunch

Untitled

Mar 27th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. #This tracks wheather to subtract or add
  2. tralse = True
  3. #This is the amount of steps we take
  4. ptr = 1
  5. #This is what I want the cow to find
  6. goal = 1000
  7. #This is the current locaiton of the "cow"
  8. location = 0
  9. #This counts the total Steps
  10. steps = 0
  11. # This tells me whether to subtract or not
  12. flag = False
  13. #Go until we reach the goal
  14. while True:
  15.     #Check wheather to subtract or add
  16.     if tralse:
  17.         #Subtract until we get to correct place to trun around and go the other way
  18.         for i in range(ptr):
  19.             #Add to location (to the right)
  20.             location += 1
  21.             #Increment the steps counter
  22.             steps += 1
  23.             #Check if we've reached the goal yet
  24.             if goal == location:
  25.                 #show the steps
  26.                 print(steps)
  27.                 #Break out
  28.                 flag = True
  29.                 break
  30.     #This is the same thing as above exept for subtracting
  31.     else:
  32.         for i in range(ptr):
  33.             steps += 1
  34.             location -= 1
  35.             if goal == location:
  36.                 print(steps)
  37.                 flag = True
  38.                 break
  39.     if flag == True:
  40.         break
  41.     tralse = not tralse
  42.     ptr *= 2
  43.  
  44.  
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement