Discrete Baker's Map
Pyth, 25 19 18 bytes
msC_dcs_Cmck/lk2Q2
Online demonstration. It uses an 2D-array of chars.
Array of strings is one char longer (19 bytes). Online demonstration
Explanation:
m Q map each string k in input:
/lk2 calculate half the line-length: len(k)/2
ck/lk2 chop k into pieces of length len(k)/2
results in two pieces
C zip the resulting list
results in a tuple ([first half of strings], [second half of strings])
_ invert the order ([second half of strings], [first half of strings])
s sum (combine the two lists to a big one
c 2 chop them into tuples
m for each tuple of strings:
sC_d invert, zip, and sum
The last part is a bit confusing at first. Let's assume we have the tuple ['DEF', 'JKL']
(I use the example from the OP).
d (('D', 'E', 'F'), ('J', 'K', 'L')) just the pair of strings
_d (('J', 'K', 'L'), ('D', 'E', 'F')) invert the order
C_d [('J', 'D'), ('K', 'E'), ('L', 'F')] zipped
sC_d ('J', 'D', 'K', 'E', 'L', 'F') sum (combine tuples)
Julia, 136 bytes
A very straightforward implementation. Not a particularly competitive entry, but it was fun!
A->(s=size(A);w=s[2];u=w÷2;C=vcat(A[:,u+1:w],A[:,1:u]);D=cell(s);j=1;for i=1:2:size(C,1) D[j,:]=vec(flipdim(C[i:i+1,:],1));j+=1end;D)
This creates a lambda function that accepts a 2-dimensional array as input and returns a transformed 2-dimensional array.
Ungolfed + explanation:
function f(A)
# Determine bounds
s = size(A) # Store the array dimensions
w = s[2] # Get the number of columns
u = w ÷ 2 # Integer division, equivalent to div(w, 2)
# Stack the right half of A atop the left
C = vcat(A[:, u+1:w], A[:, 1:u])
# Initialize the output array with the appropriate dimensions
D = cell(s)
# Initialize a row counter for D
j = 1
# Loop through all pairs of rows in C
for i = 1:2:size(C, 1)
# Flip the rows so that each column is a flipped pair
# Collapse columns into a vector and store in D
D[j, :] = vec(flipdim(C[i:i+1, :], 1))
j += 1
end
return D
end
To call it, give the function a name, e.g. f=A->(...)
.
Example output:
julia> A = ["A" "B" "C" "D" "E" "F";
"G" "H" "I" "J" "K" "L";
"M" "N" "O" "P" "Q" "R";
"S" "T" "U" "V" "W" "X"]
julia> f(A)
4x6 Array{Any,2}:
"J" "D" "K" "E" "L" "F"
"V" "P" "W" "Q" "X" "R"
"G" "A" "H" "B" "I" "C"
"S" "M" "T" "N" "U" "O"
julia> B = ["H" "e" "l" "l";
"!" " " " " "o";
"d" " " " " "-";
"l" "r" "o" "W"]
julia> f(B)
4x4 Array{Any,2}:
" " "l" "o" "l"
"o" " " "W" "-"
"!" "H" " " "e"
"l" "d" "r" " "
And proof that it can be arbitrarily chained:
julia> f(f(B))
4x4 Array{Any,2}:
"W" "o" "-" "l"
"r" " " " " "e"
"o" " " " " "l"
"l" "!" "d" "H"
Suggestions are welcome as always, and I'll happy provide any further explanation.
CJam, 25 24 bytes
qN/_0=,2/f/z~\+2/Wf%:zN*
Straight forward spec implementation. Explanation:
qN/ "Split input by rows";
_0=,2/ "Get half of length of each row";
f/ "Divide each row into two parts";
z "Convert array of row parts to array of half columns parts";
~\+ "Put the second half of columns before the first half and join";
2/ "Group adjacent rows";
Wf% "Flip the row pairs to help in CW rotation";
:z "Rotate pairwise column elements CW";
N* "Join by new line";
Try it online here