zhukov000

Untitled

Oct 31st, 2021
1,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. def def_color(x, y):
  2.     return 1 if (x + y) % 2 == 0 else 0
  3.  
  4.  
  5. def get_direction(cur_coords, target_coords):
  6.     x_dir = 0
  7.     y_dir = 0
  8.     x_s, y_s = cur_coords
  9.     x_f, y_f = target_coords
  10.     if x_f - x_s >= 0:
  11.         x_dir = 1
  12.     else:
  13.         x_dir = 0
  14.     if y_f - y_s >= 0:
  15.         y_dir = 1
  16.     else:
  17.         y_dir = 0
  18.  
  19.     return (x_dir, y_dir)
  20.  
  21.  
  22. def make_step(coords, direction):
  23.     x, y = coords
  24.     if sum(direction) == 2:
  25.         return (x + 1, y + 1)
  26.     elif sum(direction) == 0:
  27.         return (x - 1, y - 1)
  28.     else:
  29.         if direction[0] == 0:
  30.             if direction[1] == 1:
  31.                 return (x - 1, y + 1)
  32.         else:
  33.             return (x + 1, y - 1)
  34.  
  35.  
  36. def main():
  37.     start_x = int(input())
  38.     start_y = int(input())
  39.  
  40.     target_x = int(input())
  41.     target_y = int(input())
  42.  
  43.     finish_coords = (target_x, target_y)
  44.  
  45.     step_hist = [[start_x, start_y]]
  46.  
  47.     if def_color(start_x, start_y) != def_color(target_x, target_y):
  48.         print("No")
  49.         return
  50.  
  51.     while True:
  52.         direction = get_direction(step_hist[-1], finish_coords)
  53.         step_hist.append(make_step(step_hist[-1], direction))
  54.         if step_hist[-1] == finish_coords:
  55.             break
  56.  
  57.     print("Yes")
  58.     step_hist.pop(0)
  59.     print(len(step_hist))
  60.     for x, y in step_hist:
  61.         print(x, y)
  62.     return
  63.  
  64.  
  65. main()
Advertisement
Add Comment
Please, Sign In to add comment