Interleaving reversing
MATL, 8 bytes
t2L)P5M(
Try it online! Or verify all test cases.
Explanation
t % Implicit input. Duplicate
% STACK: 'abcdefghi', 'abcdefghi'
2L % Push [2, 2, 1j]. This represents 2:2:end when used as an index
% STACK: 'abcdefghi', 'abcdefghi', [2, 2, 1j]
) % Get entries at those indices
% STACK: 'abcdefghi', 'bdfh'
P % Flip
% STACK: 'abcdefghi', 'hfdb'
5M % Push [2, 2, 1j] again
% STACK: 'abcdefghi', 'hfdb', [2, 2, 1j]
( % Write entries at those indices. Implicit display
% STACK: 'ahcfedgbi'
Alice, 10 bytes
/ZY
\IOR@/
Try it online!
Half of the bytes of this program are spent on correctly formatting the source, the actual commands are just IYRZO
, because Alice has just the right builtins for this task.
Explanation
As I said, the mirrors (/\
), the newline and @
are there just to make the ip move in the right direction and terminate the program at the end. The actual code, linearised, is the following:
IYRZO
I Input a line
Y Unzip it into its even positions and its odd ones
R Reverse the odd positions
Z Zip it back again
O Output
Quite straightforward, I'd say.
Jelly, 7 bytes
s2ZU2¦Z
This is a full program.
Try it online!
How it works
s2ZU2¦Z Main link. Argument: s (string)
s2 Split s into pairs.
Z Zip/tranpose, grouping characters by the parity of their indices.
¦ Sparse application:
U Upend; reverse both strings in the pair.
2 Replace the second string with the reversed string.
Z Zip/transpose, interleaving the two strings.