Triangularity is a new esolang developed by Mr. Xcoder where code structure has to follow a very specific pattern:
- For the
n
th line of code, there must be exactly2n-1
characters of the program on it. This causes a triangular/pyramid shape, with the first line having only one character and the rest increasing by increments of 2. - Each line must be padded with
.
s on the left and right, such that the characters are centered on their lines and all lines are padded to the same length. Ifl
is defined as the number of lines in the program, each line in the program must have a length of2 * l - 1
For example, the program on the left is valid, but the program on the right isn't:
Valid | Invalid
|
...A... | ABCDE
..BCD.. | FGH
.EFGHI. | IJKLMN
JKLMNOP | OPQRS
When laid out in the valid structure, the name becomes obvious.
Task
Your task is to take a single line string as input, representing Triangularity code, and output it converted into valid code as described above.
Specifications for I/O:
- The input will only contain characters in the range
0x20 - 0x7e
- The length of the input always will be a square number and thus paddable nicely.
- You must use dots for the output padding, not something else.
You may input and output through any acceptable method. This is a code-golf so the shortest code in bytes wins!
Test cases
input
----
output
g
----
g
PcSa
----
.P.
cSa
DfJ0vCq7G
----
..D..
.fJ0.
vCq7G
7xsB8a1Oqw5fhHX0
----
...7...
..xsB..
.8a1Oq.
w5fhHX0
QNYATbkX2sKZ6IuOmofwhgaef
----
....Q....
...NYA...
..TbkX2..
.sKZ6IuO.
mofwhgaef
ABCDEF"$%& G8"F@
----
...A...
..BCD..
.EF"$%.
& G8"F@
ab.c
----
.a.
b.c
For those who know Triangularity, you'll notice from the last test case that strings don't have to be handled