Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. def calc_distance(horizontal, vertical):
  2.   steps = 0
  3.  
  4.   while vertical != 0 and horizontal != 0:
  5.     steps += 1
  6.     vertical -= (vertical/abs(vertical))/2
  7.     horizontal -= horizontal/abs(horizontal)
  8.      
  9.     if(vertical == 0):
  10.       steps += abs(horizontal)
  11.     elif(horizontal == 0):
  12.       steps += abs(vertical)
  13.    
  14.   return steps
  15.  
  16. vertical = 0
  17. horizontal = 0
  18. max_steps = 0
  19. dist = 0
  20.  
  21. for move in movement:
  22.   vertical += move[0]
  23.   horizontal += move[1]
  24.  
  25.   dist = calc_distance(horizontal, vertical)
  26.  
  27.   if(dist > max_steps):
  28.     max_steps = dist
  29.  
  30. print("Coordinates (" + str(vertical) + ", " + str(horizontal) + ")")
  31. print("Steps: " + str(dist))
  32. print("Max steps: " + str(max_steps))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement