Skip to main content
2 of 11
Various cleanup
doug
  • 1.4k
  • 3
  • 9

K (ngn/k), 337 331 315 bytes

s:{,/((#l)#("-";"")){x/y}',''l:(0,((#y)>)#+\(0,(-1+#l)#-1 1)+l:1_|1+&x#2)_y}
j:{-1_0,+\(-1+2*x)/*/1(*\'1+-2*<':')\~:\2_((#l)#!2)@&l:,/+|1(2*1+)\|!x}
f:{t:-1_@["|-"{1=1|x|-x}d;(-1+&0<l;!#y);:;(" ..''"(0<)#l:(0,,/-:\1,w:-1+2*x)?*/1(~=':)\d:-':i:j[x];y:s[x;y])],">";(x,w)#@[(x*w)#" ";(i;(-1+2*2!x)+*|i);:;(t;"<>"2!x)]}

Try it online!

-6 : Save a few bytes with shorter names.
-16 : Tidying up

doug
  • 1.4k
  • 3
  • 9