1) First we take remove character at the end of the input-string until we are left with a length that is a square (i.e. 1, 4, 9, 16, 25, 36, etc.)
abcdefghijklmnopqrstuvwxyz (length 26) becomes
abcdefghijklmnopqrstuvwxy (length 25).
2) Then we put this in a square, one line at a time, left to right:
abcde fghij klmno pqrst uvwxy
3) We fold it in all four directions, like this (we keep unfolding until the outer folded 'block' has no inner characters to unfold anymore):
m qrs l n ghi abcde ihgf jihg mn lk on lm srqp tsrq uvwxy qrs l n ghi m
Some things to note, when we fold outward, we basically mirror like this (numbers added as clarification, which represents the 'indexes' in these examples):
When we fold out the left side:
123 to: 321 123 fghij ihgf j
When we fold the right side:
123 to: 123 321 fghij f jihg
When we fold upwards:
3q 2l 1g b to: b 1g 1 2l 2 3q 3 v v
When we fold downwards:
b b 1g 1 2l 2 3q 3 v to: v 3q 2l 1g
- You can assume the input will always have at least 1 character (which will also be the output).
- Output format is flexible, so you can print to STDOUT or STDERR; return as string-array/list or character 2D-array; single string with new-lines; etc.
- The input will only contain alphanumeric characters (
- You can also use a non-alphanumeric character to fill up the spaces in and/or around the ASCII-art output, like a dot
- Trailing spaces and a single trailing new-line are optional.
- We continue unfolding until the outer folded 'block' has no more centers to unfold.
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
Input: abcdefghijklmnopqrstuvwxy Output: m qrs l n ghi abcde ihgf jihg mn lk on lm srqp tsrq uvwxy qrs l n ghi m Input: A Ouput: A Input: ThisIsATest Output: I Thi Is sI ATe I Input: HowAboutAVeryLongExampleWhichIsAlsoAnEvenSquareInsteadOfOddOneAndExceeds64Chars Output: An ch xamp i I o E quar steadO S e s v h s E l VeryLo HowAbout oLyreVA noLyreV xampl Eg el Examp hci Is hW As hi Ihc nAo Ev sl ev so EnA quare Sn Ie Squar Odaetsn fOdaets OddOneAn steadO S e s v h s E l VeryLo xamp i I o E quar An ch Input: Lenght7 Output: Le ng Input: abc Output: a