Advertisement
Guest User

Codingame Power of Thor 1 with dict and lambda function

a guest
May 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. moves =\
  2. {
  3.     (0, -1): "N",
  4.     (1, -1): "NE",
  5.     (1, 0): "E",
  6.     (1, 1): "SE",
  7.     (0, 1): "S",
  8.     (-1, 1): "SW",
  9.     (-1, 0): "W",
  10.     (-1, -1): "NW"
  11. }
  12.  
  13. init_input = input().split()
  14.  
  15. dist_x = int(init_input[0]) - int(init_input[2])
  16. dist_y = int(init_input[1]) - int(init_input[3])
  17.  
  18. sign = lambda x: (x > 0) - (x < 0)
  19.  
  20. while dist_x or dist_y:
  21.     mx, my = sign(dist_x), sign(dist_y)
  22.     print(moves[(mx, my)])
  23.     dist_x -= mx
  24.     dist_y -= my
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement