Let's observe the following string:
If we swap the ends of the string, which are these:
ABCDEFGHIJKLMNOP ^^ ^^
We get the following result:
After that, we delete the ends of the string, which in this case are
O. The result is:
If we repeat the process, we get the following list:
N Result 2 ADEFGHIJKLMP 3 AEFGHIJKLP 4 AFGHIJKP 5 AGHIJP 6 AHIP 7 AP
You can see that for N = 5, the result is
AGHIJP. At N = 7, the length of the string is smaller than 3, so N > 7 is considered invalid in this case.
Given a string S with at least length 4 and the number of repetitions N > 0, output the final result. You can assume that N is always valid.
Input > Output N = 3, S = ABCDEFGHIJKLMNOP > AEFGHIJKLP N = 1, S = Hello > Hlo N = 2, S = 123321 > 11
This is code-golf, so the submission with the least amount of bytes wins! For the simplicity, you can assume that the string will only contain alphanumeric characters.