Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def LostCow(goal):
- flag = False
- tralse = True
- steps = 0
- location = 0
- ptr = 1
- 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
- return(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:
- return(steps)
- flag = True
- break
- if flag == True:
- break
- tralse = not tralse
- ptr *= 2
- add = 0
- for i in range(1,1001):
- add += LostCow(i)
- for i in range(1,1001):
- add += LostCow(0-i)
- add /= 200
- print(add)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement