Ruby, (削除) 173 (削除ここまで) 163 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=' '*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Commented code
->s{u=1;m=v=0 #Setup u,v as a direction vector 0,1,0. m=max value of x position.
a=(0..w=n=3*x=y=s.size #w=width of board, 3*input length. n=min value of x position.
).map{Q=' '*w} #Make board a of w strings Q of w spaces. Move to x,y both equal input length.
s.chars{|i| #iterate through characters in input
(j='\ /'.index i)? #j=index of \ or / (either 0 or 2, true) or false if other character.
(u,v=v*k=1-j,u*k): #If true, k=1 or -1. swap u and v, and negate with k if /.
(a[y+=v][x+=u]=i #If false, update x,y by moving by u,v. Edit the character into a and...
m=x>m ?x:m;n=x<n ?x:n)#...if x outside the bounds n..m, update n or m
} #(conditional 1 byte shorter than min/max.) Close loop.
(a-[Q]).map{|h|h[n..m]}#delete blank rows Q from a. Cut section h[n..m] from each remaining string.
} #return from function with result of last calculation.
Ruby, (削除) 173 (削除ここまで) 163 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=' '*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Commented code
->s{u=1;m=v=0 #Setup u,v as a direction vector 0,1 m=max value of x position.
a=(0..w=n=3*x=y=s.size #w=width of board, 3*input length. n=min value of x position.
).map{Q=' '*w} #Make board a of w strings Q of w spaces. Move to x,y both equal input length.
s.chars{|i| #iterate through characters in input
(j='\ /'.index i)? #j=index of \ or / (either 0 or 2, true) or false if other character.
(u,v=v*k=1-j,u*k): #If true, k=1 or -1. swap u and v, and negate with k if /.
(a[y+=v][x+=u]=i #If false, update x,y by moving by u,v. Edit the character into a and...
m=x>m ?x:m;n=x<n ?x:n)#...if x outside the bounds n..m, update n or m
} #(conditional 1 byte shorter than min/max.) Close loop.
(a-[Q]).map{|h|h[n..m]}#delete blank rows Q from a. Cut section h[n..m] from each remaining string.
} #return from function with result of last calculation.
Ruby, (削除) 173 (削除ここまで) 163 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=' '*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Commented code
->s{u=1;m=v=0 #Setup u,v as a direction vector 1,0. m=max value of x position.
a=(0..w=n=3*x=y=s.size #w=width of board, 3*input length. n=min value of x position.
).map{Q=' '*w} #Make board a of w strings Q of w spaces. Move to x,y both equal input length.
s.chars{|i| #iterate through characters in input
(j='\ /'.index i)? #j=index of \ or / (either 0 or 2, true) or false if other character.
(u,v=v*k=1-j,u*k): #If true, k=1 or -1. swap u and v, and negate with k if /.
(a[y+=v][x+=u]=i #If false, update x,y by moving by u,v. Edit the character into a and...
m=x>m ?x:m;n=x<n ?x:n)#...if x outside the bounds n..m, update n or m
} #(conditional 1 byte shorter than min/max.) Close loop.
(a-[Q]).map{|h|h[n..m]}#delete blank rows Q from a. Cut section h[n..m] from each remaining string.
} #return from function with result of last calculation.
Ruby, (削除) 173 (削除ここまで) 162163 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=?.*wQ=' '*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Commented code
->s{u=1;m=v=0 #Setup u,v as a direction vector 0,1 m=max value of x position.
a=(0..w=n=3*x=y=s.size #w=width of board, 3*input length. n=min value of x position.
).map{Q=' '*w} #Make board a of w strings Q of w spaces. Move to x,y both equal input length.
s.chars{|i| #iterate through characters in input
(j='\ /'.index i)? #j=index of \ or / (either 0 or 2, true) or false if other character.
(u,v=v*k=1-j,u*k): #If true, k=1 or -1. swap u and v, and negate with k if /.
(a[y+=v][x+=u]=i #If false, update x,y by moving by u,v. Edit the character into a and...
m=x>m ?x:m;n=x<n ?x:n)#...if x outside the bounds n..m, update n or m
} #(conditional 1 byte shorter than min/max.) Close loop.
(a-[Q]).map{|h|h[n..m]}#delete blank rows Q from a. Cut section h[n..m] from each remaining string.
} #return from function with result of last calculation.
Ruby, (削除) 173 (削除ここまで) 162 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=?.*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Commented code
->s{u=1;m=v=0 #Setup u,v as a direction vector 0,1 m=max value of x position.
a=(0..w=n=3*x=y=s.size #w=width of board, 3*input length. n=min value of x position.
).map{Q=' '*w} #Make board a of w strings Q of w spaces. Move to x,y both equal input length.
s.chars{|i| #iterate through characters in input
(j='\ /'.index i)? #j=index of \ or / (either 0 or 2, true) or false if other character.
(u,v=v*k=1-j,u*k): #If true, k=1 or -1. swap u and v, and negate with k if /.
(a[y+=v][x+=u]=i #If false, update x,y by moving by u,v. Edit the character into a and...
m=x>m ?x:m;n=x<n ?x:n)#...if x outside the bounds n..m, update n or m
} #(conditional 1 byte shorter than min/max.) Close loop.
(a-[Q]).map{|h|h[n..m]}#delete blank rows Q from a. Cut section h[n..m] from each remaining string.
} #return from function with result of last calculation.
Ruby, (削除) 173 (削除ここまで) 163 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=' '*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Commented code
->s{u=1;m=v=0 #Setup u,v as a direction vector 0,1 m=max value of x position.
a=(0..w=n=3*x=y=s.size #w=width of board, 3*input length. n=min value of x position.
).map{Q=' '*w} #Make board a of w strings Q of w spaces. Move to x,y both equal input length.
s.chars{|i| #iterate through characters in input
(j='\ /'.index i)? #j=index of \ or / (either 0 or 2, true) or false if other character.
(u,v=v*k=1-j,u*k): #If true, k=1 or -1. swap u and v, and negate with k if /.
(a[y+=v][x+=u]=i #If false, update x,y by moving by u,v. Edit the character into a and...
m=x>m ?x:m;n=x<n ?x:n)#...if x outside the bounds n..m, update n or m
} #(conditional 1 byte shorter than min/max.) Close loop.
(a-[Q]).map{|h|h[n..m]}#delete blank rows Q from a. Cut section h[n..m] from each remaining string.
} #return from function with result of last calculation.
Ruby, (削除) 162173 (削除ここまで) 173162 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=?.*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Commented code
->s{u=1;m=v=0 #Setup u,v as a direction vector 0,1 m=max value of x position.
a=(0..w=n=3*x=y=s.size #w=width of board, 3*input length. n=min value of x position.
).map{Q=' '*w} #Make board a of w strings Q of w spaces. Move to x,y both equal input length.
s.chars{|i| #iterate through characters in input
(j='\ /'.index i)? #j=index of \ or / (either 0 or 2, true) or false if other character.
(u,v=v*k=1-j,u*k): #If true, k=1 or -1. swap u and v, and negate with k if /.
(a[y+=v][x+=u]=i #If false, update x,y by moving by u,v. Edit the character into a and...
m=x>m ?x:m;n=x<n ?x:n)#...if x outside the bounds n..m, update n or m
} #(conditional 1 byte shorter than min/max.) Close loop.
(a-[Q]).map{|h|h[n..m]}#delete blank rows Q from a. Cut section h[n..m] from each remaining string.
} #return from function with result of last calculation.
Ruby, (削除) 162 (削除ここまで) 173 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=?.*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Ruby, (削除) 173 (削除ここまで) 162 bytes
->s{u=1;m=v=0
a=(0..w=n=3*x=y=s.size).map{Q=?.*w}
s.chars{|i|(j='\ /'.index i)?(u,v=v*k=1-j,u*k):(a[y+=v][x+=u]=i
m=x>m ?x:m;n=x<n ?x:n)}
(a-[Q]).map{|h|h[n..m]}}
Commented code
->s{u=1;m=v=0 #Setup u,v as a direction vector 0,1 m=max value of x position.
a=(0..w=n=3*x=y=s.size #w=width of board, 3*input length. n=min value of x position.
).map{Q=' '*w} #Make board a of w strings Q of w spaces. Move to x,y both equal input length.
s.chars{|i| #iterate through characters in input
(j='\ /'.index i)? #j=index of \ or / (either 0 or 2, true) or false if other character.
(u,v=v*k=1-j,u*k): #If true, k=1 or -1. swap u and v, and negate with k if /.
(a[y+=v][x+=u]=i #If false, update x,y by moving by u,v. Edit the character into a and...
m=x>m ?x:m;n=x<n ?x:n)#...if x outside the bounds n..m, update n or m
} #(conditional 1 byte shorter than min/max.) Close loop.
(a-[Q]).map{|h|h[n..m]}#delete blank rows Q from a. Cut section h[n..m] from each remaining string.
} #return from function with result of last calculation.
Loading
Loading