fork(2) download
  1. from math import *
  2. def F(x):s='%.3g'%x;s=[s+'.',s]['.'in s]+'00';return[s[:3],s[:4]]['.'in s[:3]]
  3. I=input()
  4. V=I.split('\n');l=max(len(x)for x in V);V=[x.ljust(l)for x in V];N=len(V)
  5. for i in range(N):
  6. for j in range(l):
  7. c=V[i][j]
  8. if(c in'<>'and'|'not in V[max(0,i-1)][j]+V[min(N-1,i+1)][j])+(c in'^v'and'-'not in V[i][max(0,j-1)]+V[i][min(l-1,j+1)]):h=(i,j)
  9. if c=='x':x=(i,j)
  10. Y=x[0]-h[0];X=h[1]-x[1];a=atan2(Y,X)/pi*180%360
  11. print[F(hypot(X,Y))+' units @ '+F(a)+' degrees '+{0:'E',90:'N',180:'W',270:'S'}.get(a,['NE','NW','SW','SE'][int(a/90)]),''][I=='x']
Success #stdin #stdout 0.02s 9024KB
stdin
"<--------------^\n               |\n               |\n               x"
stdout
15.3 units @ 169 degrees NW