05AB1E, 17 bytes
12 bytes if trailing whitespaces were allowed: try it online.
ζε2úíJNúS}ζJðδÜõÜ
Port of @Shaggy's Japt answer.
Input as a list of list of characters; output as a list of lines.
More interesting answer using the Canvas builtin ((削除) 27 (削除ここまで) 25 bytes):
(削除) 20 (削除ここまで) 19 bytes if trailing whitespaces were allowed: try it online.
€gDø4.ý ̃I€ûðoý374S.Λ¶¡ðδÜ
-2 bytes thanks to @emanresuA.
Input as a list of words; output as a list of lines.
Explanation:
ζ # Zip/transpose; swapping rows/columns of the (implicit) input-list of lists
# of characters, with a space " " as filler for shorter lists
ε # Map over each inner lists of characters:
2ú # Pad each inner character with 2 leading spaces
í # Reverse each inner string, so the spaces are trailing
J # Join this list together to a single string
Nú # Pad the 0-based map-index amount of leading spaces
S # Convert the string back to a list of characters
}ζ # After the map: Zip/transpose back again with " " filler
J # Join each inner list together to a single string
δ # Map over each inner line:
ð Ü # Trim trailing spaces
õÜ # Trim trailing empty strings from the list
# (after which the list of lines is output implicitly)
€gDø4.ý ̃I€ûðoý374S.Λ¶¡ðδÜ
€g # Get the length of each word of the (implicit) input-list
Dø # Convert each value to a pair of this value with a Duplicate + Zip/transpose
4.ý # Intersperse this list of pairs with 4 as delimiter
̃ # Flatten it to a single list
I # Push the input-list of words again
€û # Palindromize each word
ðoý # Join this list with " " (2 spaces) delimiter
ŽDā # Push 374
S # Convert it to a list of digits: [3,7,4]
.Λ # Use the modifiable Canvas builtin with these three arguments
¶¡ # Split it on newlines
δ # Map over each inner line:
ð Ü # Trim trailing spaces
# (after which the list of lines is output implicitly)
Additional information about the Canvas builtin Λ/.Λ:
It takes 3 arguments to draw an ASCII shape:
- Length of the lines we want to draw
- Character/string to draw
- The direction to draw in, where each digit represents a certain direction:
7 0 1
↖ ↑ ↗
6 ← X → 2
↙ ↓ ↘
5 4 3
€gDø4.ý ̃I€ûðoý374S creates the following Canvas arguments:
- Lengths (
€gDø4.ý ̃): e.g.[11,11,4,7,7,4,3,3,4,4,4,4,4,4]for input["programming","puzzles","and","code","golf"] - Characters (
I€ûðoý): e.g."programmingnimmargorp puzzleselzzup andna codedoc golflog"for input["programming","puzzles","and","code","golf"] - Directions (
374S):[3,7,4], which translates to \$[↘,↖,↓]\$
Because we have a list of lengths, those are leading here.
Step 1: Draw 11 characters ("programming") in direction 3 (\$↘\$):
p
r
o
g
r
a
m
m
i
n
g
Step 2: Draw 11-1 characters ("nimmargorp") in direction 7 (\$↖\$):
p
r
o
g
r
a
m
m
i
n
g
Step 3: Draw 4-1 characters (" p") in direction 4 (\$↓\$):
p
r
p o
g
r
a
m
m
i
n
g
Step 4: Draw 7-1 characters ("uzzles") in direction 3 (\$↘\$):
p
r
p o
u g
z r
z a
l m
e m
s i
n
g
etc.
See this 05AB1E tip of mine for an in-depth explanation of the Canvas builtin.
€gDø4.ý ̃ could alternatively be εgD4)} ̃ ̈ or €gDø4ドル¦ ̃, but I've been unable to find anything shorter.
- 136.2k
- 14
- 154
- 394