Given an input string of length 2
or longer consisting solely of alphabetical characters [A-Z]
or [a-z]
(your choice if they're all uppercase or all lowercase), output a continuous string of characters forming a double diamond pattern.
The input string starts on the center line and extends down-and-right at a diagonal until the end of the input string is reached. Then, the pattern continues up-and-right at a diagonal until you're as far above the center line as the length of the input string minus 1. Continue down-and-right back to the center line, then down-and-left, then up-and-left (going "behind" the center character), and finally down-and-left back to the starting character.
That's a little wordy, and it's better demonstrated by some examples:
"YOU"
U Y
Y O U O
Y O U
O Y U Y
U O
^ ^
↙ ↖ ↗ ↘
↘ ↗ >
↘ ↗ ↖ ↙
V V
See how the YOU
starts at the center line and follows down-and-right, then up-and-right, etc., until it loops back to the beginning. Note especially how the Y
on the up-and-left portion is "behind" the O
and therefore not shown.
Some further examples:
"HI"
I I
H H H
I I
"TEST"
E E
S T T S
T T T T
T S T
E E E E
S T T S
T T
"HELLO"
L L
O L E L
H E H O
E H O H
H L E
E L L L
L E L L
L H E O
O H
- Input and output can be given by any convenient method.
- The input is guaranteed to be at least two letters long (i.e., you'll never receive
""
as input). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately (e.g., feel free to pad as a rectangle).
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.