Guest User

Golf for http://codegolf.stackexchange.com/a/98834/48878

a guest
Nov 7th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. i=[list(x)for x in inputtt.split('\n')]
  2.  
  3. r,c,s,q,e,w=(0,)*6
  4. # ->
  5. r=c=s=q=e=w=0
  6.  
  7. o=lambda y,x:0<=x<len(i[0])and 0<=y<len(i)
  8. # ->
  9. o=lambda y,x:len(i[0])>x>=0<=y<len(i)
  10.  
  11. d='\\/_|'
  12. # ->   ('\/' == '\\/')
  13. d='\/_|'
  14.  
  15. for l in i:
  16.  if l.count('x'):r=i.index(l);c=l.index('x')
  17. for a,b in(1,0),(0,1),(-1,0),(0,-1):
  18.  
  19.  y,x=r+a,c+b;f=0
  20.  if o(y,x):f=i[y][x]
  21.  # -->
  22.  y,x=r+a,c+b;f=o(y,x)and i[y][x]
  23.  
  24.  if f in d:s=f;w=d.index(f);q,e=y,x
  25. k=lambda y,x,g=[1,1,0,1][w],v=[1,-1,1,0][w]:o(y,x)and i[y][x]==s and(exec('i[y][x]=0')==0)+1+k(y+g,x+v)+k(y-g,x-v)
  26. # ->
  27.                                                                  and exec('i[y][x]=0')or 1+k(y+g,x+v)+k(y-g,x-v)
  28. print(k(q,e))
Add Comment
Please, Sign In to add comment