Advertisement
SoggyCrunch

Untitled

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