Skip to main content
added 4 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 317 300 298298 290 bytes

def f(w,h,B):
 A=[w*[2]forA=[w*[-1]for c in' '*h];p=w+h
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*p):
	x,y,u,v=[[[d=[[[(0,2*p+~i,1,0),(w+p+~i,h-1,0,-1)][i<w+p],(w-1,i-w,-1,03)][i<p],(i,0,0,12)][i<w]
	while w>x>=0<=y<h:ud^=1+A[y][x];x+=[1,v=[(-v0,-u)0,(v-1][d];y+=[0,u)-1,(u1,v)][A[y][x]];x+=u;y+=v0][d]
	print[[y+w,2*p+~y][x<0],[w+p+~x,x][y<h]][u==0]x][y<h]][0<d<3],

Try it online!Try it online!

Takes the bumpers as a list of tuples (x,y,c)where x and y are the coordinates of the bumper and c is either \ or /.

Python 2, 317 300 298 bytes

def f(w,h,B):
 A=[w*[2]for c in' '*h];p=w+h
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*p):
	x,y,u,v=[[[(0,2*p+~i,1,0),(w+p+~i,h-1,0,-1)][i<w+p],(w-1,i-w,-1,0)][i<p],(i,0,0,1)][i<w]
	while w>x>=0<=y<h:u,v=[(-v,-u),(v,u),(u,v)][A[y][x]];x+=u;y+=v
	print[[y+w,2*p+~y][x<0],[w+p+~x,x][y<h]][u==0],

Try it online!

Python 2, 317 300 298 290 bytes

def f(w,h,B):
 A=[w*[-1]for c in' '*h];p=w+h
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*p):
	x,y,d=[[[(0,2*p+~i,0),(w+p+~i,h-1,1)][i<w+p],(w-1,i-w,3)][i<p],(i,0,2)][i<w]
	while w>x>=0<=y<h:d^=1+A[y][x];x+=[1,0,0,-1][d];y+=[0,-1,1,0][d]
	print[[y+w,2*p+~y][x<0],[w+p+~x,x][y<h]][0<d<3],

Try it online!

Takes the bumpers as a list of tuples (x,y,c)where x and y are the coordinates of the bumper and c is either \ or /.

added 4 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 317 300300 298 bytes

def f(w,h,B):
 A=[w*[2]for c in' '*h];p=w+h
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*p):
	x,y,u,v=[[[(0,2*p+~i,1,0),(w+p+~i,h-1,0,-1)][i<w+p],(w-1,i-w,-1,0)][i<p],(i,0,0,1)][i<w]
	while w>x>=0<=y<h:u,v=[(-v,-u),(v,u),(u,v)][A[y][x]];x+=u;y+=v
	print[[y+w,2*p+~y][x<0],[w+p+~x,x][y<h]][w>x>=0]x][y<h]][u==0],

Try it online!Try it online!

Python 2, 317 300 bytes

def f(w,h,B):
 A=[w*[2]for c in' '*h];p=w+h
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*p):
	x,y,u,v=[[[(0,2*p+~i,1,0),(w+p+~i,h-1,0,-1)][i<w+p],(w-1,i-w,-1,0)][i<p],(i,0,0,1)][i<w]
	while w>x>=0<=y<h:u,v=[(-v,-u),(v,u),(u,v)][A[y][x]];x+=u;y+=v
	print[[y+w,2*p+~y][x<0],[w+p+~x,x][y<h]][w>x>=0],

Try it online!

Python 2, 317 300 298 bytes

def f(w,h,B):
 A=[w*[2]for c in' '*h];p=w+h
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*p):
	x,y,u,v=[[[(0,2*p+~i,1,0),(w+p+~i,h-1,0,-1)][i<w+p],(w-1,i-w,-1,0)][i<p],(i,0,0,1)][i<w]
	while w>x>=0<=y<h:u,v=[(-v,-u),(v,u),(u,v)][A[y][x]];x+=u;y+=v
	print[[y+w,2*p+~y][x<0],[w+p+~x,x][y<h]][u==0],

Try it online!

deleted 17 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 317317 300 bytes

def f(w,h,B):
 A=[w*[2]for c in' '*h]'*h];p=w+h
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*(w+h)2*p):
	x,y,u,v=[[[(0,2*w+2*h-i-12*p+~i,1,0),(2*w+h-1-iw+p+~i,h-1,0,-1)][i<2*w+h]][i<w+p],(w-1,i-w,-1,0)][i<w+h]][i<p],(i,0,0,1)][i<w]
	while w>x>=0<=y<h:u,v=[(-v,-u),(v,u),(u,v)][A[y][x]];x+=u;y+=v
	print[[y+w,2*(w+h)+~y][x<0]2*p+~y][x<0],[2*w+h-1-x[w+p+~x,x][y<h]][w>x>=0],

Try it online!Try it online!

Python 2, 317 bytes

def f(w,h,B):
 A=[w*[2]for c in' '*h]
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*(w+h)):
	x,y,u,v=[[[(0,2*w+2*h-i-1,1,0),(2*w+h-1-i,h-1,0,-1)][i<2*w+h],(w-1,i-w,-1,0)][i<w+h],(i,0,0,1)][i<w]
	while w>x>=0<=y<h:u,v=[(-v,-u),(v,u),(u,v)][A[y][x]];x+=u;y+=v
	print[[y+w,2*(w+h)+~y][x<0],[2*w+h-1-x,x][y<h]][w>x>=0],

Try it online!

Python 2, 317 300 bytes

def f(w,h,B):
 A=[w*[2]for c in' '*h];p=w+h
 for x,y,c in B:A[y][x]=c<'0'
 for i in range(2*p):
	x,y,u,v=[[[(0,2*p+~i,1,0),(w+p+~i,h-1,0,-1)][i<w+p],(w-1,i-w,-1,0)][i<p],(i,0,0,1)][i<w]
	while w>x>=0<=y<h:u,v=[(-v,-u),(v,u),(u,v)][A[y][x]];x+=u;y+=v
	print[[y+w,2*p+~y][x<0],[w+p+~x,x][y<h]][w>x>=0],

Try it online!

Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39
Loading