Advertisement
lexquarkie

power_of_thor codingame_quarkie 26.02

Feb 27th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. #quarkie 26.02
  2. import math
  3.  
  4. LX, LY, TX, TY = [int(i) for i in input().split()]
  5.  
  6. dists = [] #distances from neighbor positions
  7. directions = ['N',  'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
  8. changes = [[0,-1],[+1,-1], [+1,0], [+1,1], [0,1], [-1,1], [-1,0], [-1,-1], ]
  9.  
  10. dist =  lambda LX, LY, TX, TY : math.sqrt(pow(abs(LX-TX),2) +  pow(abs(LY-TY),2) )
  11.  
  12. def dists_fill(LX, LY, TX, TY):
  13.     del dists[:]
  14.     for i in changes:
  15.         dists.append(dist(LX, LY, TX+i[0], TY+i[1]))  # create a distances on directions
  16.     return dists
  17.  
  18. while 1:
  19.     dir = directions[ dists_fill(LX,LY,TX,TY).index( min( dists )) ]
  20.     print(dir)
  21.     TX += changes[directions.index(dir)][0]
  22.     TY += changes[directions.index(dir)][1]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement