Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 5 characters in body
Source Link
TFeld
  • 19.9k
  • 3
  • 21
  • 63

Python 3, 289(削除) 289 (削除ここまで) 286 bytes

l,u=eval(input())
_,_*_,w,h=map(max,zip(*l))
r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=(i<XQ=i<X,y<j,x<i,j<Y);r[j][i]=u[sumj<Y;r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online! Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1), along with the pipedrawing characters as follows: " ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))

Python 3, 289 bytes

l,u=eval(input())
_,_,w,h=map(max,zip(*l))
r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=(i<X,y<j,x<i,j<Y);r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1), along with the pipedrawing characters as follows: " ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))

Python 3, (削除) 289 (削除ここまで) 286 bytes

l,u=eval(input())
*_,w,h=map(max,zip(*l))
r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=i<X,y<j,x<i,j<Y;r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1), along with the pipedrawing characters as follows: " ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))
added 24 characters in body
Source Link
TFeld
  • 19.9k
  • 3
  • 21
  • 63

Python 3, (削除) 544 (削除ここまで) 533289 bytes (373 chars)

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
l=evall,u=eval(input())
_,_,w,h=map(max,zip(*l))
r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=(i<X,y<j,x<i,j<Y);r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online! Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1), along with the pipedrawing characters as follows: " ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))

Python 3, (削除) 544 (削除ここまで) 533 bytes (373 chars)

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
l=eval(input())
_,_,w,h=map(max,zip(*l))
r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=(i<X,y<j,x<i,j<Y);r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1)

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))

Python 3, 289 bytes

l,u=eval(input())
_,_,w,h=map(max,zip(*l))
r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=(i<X,y<j,x<i,j<Y);r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1), along with the pipedrawing characters as follows: " ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))
deleted 1 character in body
Source Link
TFeld
  • 19.9k
  • 3
  • 21
  • 63

Python 3, (削除) 544 (削除ここまで) 536533 bytes (376373 chars)

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
l=eval(input())
_,_,w,h=[*maph=map(max,zip(*l))][2:];r=[*map
r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=(i<X,y<j,x<i,j<Y);r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online! Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1)

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))

Python 3, (削除) 544 (削除ここまで) 536 bytes (376 chars)

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
l=eval(input())
w,h=[*map(max,zip(*l))][2:];r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=(i<X,y<j,x<i,j<Y);r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1)

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))

Python 3, (削除) 544 (削除ここまで) 533 bytes (373 chars)

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
l=eval(input())
_,_,w,h=map(max,zip(*l))
r=[*map(list,[' '*-~w]*-~h)]
R=range
for x,y,X,Y in l:
 for i in R(x,X+1):
 for j in R(y,Y+1):Q=(i<X,y<j,x<i,j<Y);r[j][i]=u[sum(3**o*max(Q[o]*[j in(y,Y),i in(x,X)][o%2]*2,u.index(r[j][i])//3**o%3-Q[o])for o in R(4))]
for l in r:print(''.join(l))

Try it online!

Takes input as a list of 4-tuples: (x0, y0, x1, y1)

Supports boxes of zero width or height (uses all box drawing chars).

Based on my answer to this question, but modified to alter existing boxes when drawing.

'Ungolfed':

u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
#Create array of spaces:
l=eval(input())
w,h=list(map(max,zip(*l)))[2:]
r=[[' ']*w for _ in' '*h]
for x,y,X,Y in l:
 n,m=X-1,Y-1
 for i in range(x,X):
 for j in range(y,Y):
 A,B=j in(y,m),i in(x,n)
 P=(i<n*A,y<j*B,x<i*A,j<m*B) # Pipe sides of the new box
 Q=(i<n,y<j,x<i,j<m) # Pipe sides that are inside the new box, and should be thinned.
 # Get new pipe (sides of new box, on top of thinned pipes of existing boxes. (u.index... is existing pipe))
 l=sum(3**o*max(P[o]*2,(u.index(r[j][i])//3**o%3)-Q[o])for o in range(4))
 #Add to 'canvas'
 r[j][i]=u[l]
 
print('\n'.join(''.join(l)for l in r))
deleted 7 characters in body
Source Link
TFeld
  • 19.9k
  • 3
  • 21
  • 63
Loading
added 1136 characters in body
Source Link
TFeld
  • 19.9k
  • 3
  • 21
  • 63
Loading
Source Link
TFeld
  • 19.9k
  • 3
  • 21
  • 63
Loading

AltStyle によって変換されたページ (->オリジナル) /