Unfurl a string
SOGL V0.12, 21 20 19 18 17 bytes
ø;[;ο⁴№č▓┼№TJι;jI
Try it Here! (→
added because this expects input on the stack)
Explanation:
ø;[;ο⁴№č▓┼№TJι;jI
ø; push an empty string below the input stack with the input GFE,HID,ABC
[ while [ToS (the array) isn't empty] do ["", [["G","F","E"],["H","I","D"],["A","B","C"]]]
stack at the second time looping
; duplicate 2nd from top [[[H,G], [I,F], [D,E]], "ABC"]
ο wrap it in an array [[[H,G], [I,F], [D,E]], ["ABC"]]
⁴ duplicate 2nd from top [[[H,G], [I,F], [D,E]], ["ABC"], [[H,G], [I,F], [D,E]]]
№ reverse vertically [[[H,G], [I,F], [D,E]], ["ABC"], [[D,E], [I,F], [H,G]]]
č▓ join the inner arrays (┼ fails otherwise) [[[H,G], [I,F], [D,E]], ["ABC"], ["DE", "IF", "HG"]]
┼ add the 2 parts together [[[H,G], [I,F], [D,E]], ["ABCDE", " IF", " HG"]]
№ reverse vertically again [[[H,G], [I,F], [D,E]], [" HG", " IF", "ABCDE"]]
T print that without popping [[[H,G], [I,F], [D,E]], [" HG", " IF", "ABCDE"]]
J take the last line off [[[H,G], [I,F], [D,E]], [" HG", " IF"], "ABCDE"]
ι remove the rest of the array [[[H,G], [I,F], [D,E]], "ABCDE"]
;j remove the last line of the original array ["ABCDE", [[H,G], [I,F]]]
I rotate it clockwise ["ABCDE", [[I,H], [F,G]]]
Python 2, 209 207 205 203 202 201 200 196 bytes
-4 bytes thanks to @Quelklef!
s=input();l=len;k=''.join;exec"print s;s=[x for x in[' '*l(s[0])+k(x[:-1]for x in s[-2::-1])[t::l(s[0])-1]for t in range(l(s[0]))][:-1]+[s[-1]+k(x[-1]for x in s)[-2::-1]]if x.strip()];"*(2*l(s)-1)
Try it online!
Python 2, 219 217 215 213 212 211 207 bytes
s=input();l=len;k=''.join;exec"print'\\n'.join(s);s=[x for x in[' '*l(s[0])+k(x[:-1]for x in s[-2::-1])[t::l(s[0])-1]for t in range(l(s[0]))][:-1]+[s[-1]+k(x[-1]for x in s)[-2::-1]]if x.strip()];"*(2*l(s)-1)
Try it online!
The first one outputs as a list of Strings, the second one outputs as ASCII-art.
Charcoal, 42 35 bytes
AEθSθW⊟θ«⪫θ¶AEι⮌⪫Eθ§μλωθ⊞υι↙←⮌⪫υωD⎚
Try it online! Link is to verbose version of code. Edit: Saved 7 bytes mostly by switching from character arrays to strings. Explanation:
AEθSθ
Read the input square as an array of strings into the variable q
.
W⊟θ«
While the last string in the array is not empty, remove it.
⪫θ¶
Print the rest of the array.
AEι⮌⪫Eθ§μλωθ
Rotate the rest of the array by looping through each character of the last string and joining the l
th character of every remaining string in the reversed array.
⊞υι↙←⮌⪫υω
Append the previously removed last string to u
, which holds the unfurled value, and print it.
D⎚
Output the result and then clear the canvas ready for the next iteration.
Note that this version outputs the final unfurl on a separate line, if this is undesirable then for 38 bytes:
AEθSθW⊟θ«⊞υι←E⁺⟦⪫υω⟧⮌θ⮌κAEι⮌⪫Eθ§μλωθD⎚
Try it online! Link is to verbose version of code. Explanation: ←E⁺⟦⪫υω⟧⮌θ⮌κ
reverses the current array, prepends the unfurled line, then reverses the characters in each line, then prints everything upside-down, thus producing the desired result.