The Baker's map is an important dynamical system that exhibits chaotic behavior. It is a function from the unit square to itself defined intuitively as follows.
- Cut the square vertically in half, resulting in two rectangles of size
- Stack the right half on top of the left, resulting in one rectangle of size
- Compress the rectangle back into a
In this challenge, you'll implement a discrete version of this transformation.
Input and Output
Your input is a 2D array of printable ASCII characters and whitespace of size
2m×2n for some
m, n > 0.
Your output is a similar array obtained as follows, using the
ABCDEF GHIJKL MNOPQR STUVWX
as an example. First, stack the right half of the array on top of the left half:
DEF JKL PQR VWX ABC GHI MNO STU
Then, split the columns into pairs of characters, and independently turn each pair 90 degrees clockwise, "compressing" the tall rectangle back to the original shape:
JDKELF VPWQXR GAHBIC SMTNUO
This is the correct output for the above array.
The input and output formats are flexible. You can use newline-delimited strings, lists of strings, or 2D arrays of characters. However, the input and output must have the exact same format: you must be able to iterate your submission an arbitrary number of times on any valid input.
You can write either a full program or a function. The lowest byte count wins, and standard loopholes are disallowed.
Input: 12 34 Output: 42 31 Input: Hell ! o d - lroW Output: lol o W- !H e ldr Input: ABCDEF GHIJKL MNOPQR STUVWX Output: JDKELF VPWQXR GAHBIC SMTNUO Input: *___ ___ o o|__) |__) * *| | o o __ __ * *| | _ o o|__ |__| * Output: |_____) *o |_ _ *o ||_ __| *o o*|_____) o* |_ _ o*||_ _