Alice's ordinal formatting

Alice, 28 bytes

/mY. zm~wZ.k;
\I;'!*?RR.OY@/

Try it online!

If the input length is odd, this puts the padding space at the end of the linearised program, which ends up being the first character of the output.

Leo wrote an Ordinal formatter in Alice a few days ago. After adding support for odd-length inputs and then removing some stuff that wasn't necessary for this challenge, we ended up at 28 bytes. I wanted to try a slightly different approach, which is this answer. Unfortunately, it just ended up tying 28 bytes, but at least this way I can post my own solution and let Leo post his original algorithm.

This does use Leo's really clever idea to split a string in half with ..Y;m;.!z?~.

Explanation

Let's assume that the input has even length (because we'll just pad it with a space if it doesn't). The pattern is a bit easier to see if we use 0123456789 as the code. The required output would be:

91735
08264

So the first line contains all odd positions of the input and the second line all the even inputs. Furthermore, if we reverse the odd positions, then the lines itself are both the first half (possibly longer) interleaved with the reverse of second half.

So the basic idea is:

  • Separate input into odd and even positions.
  • Pad the odd positions with a space if necessary.
  • Reverse the odd positions.
  • Then twice: halve the current string, reverse the second half, interleave both halves, print with trailing linefeed.

As for the code, this looks a lot like the kind of layout we're producing in this challenge, but it's subtly different: when the IP hits the / at the end of the code it gets reflected east, not south. Then, while in Cardinal mode, the IP will wrap around to the first column. The \ there re-enters Ordinal mode, so that the second half of the code doesn't go from right to left here, but from left to right as well. This is beneficial when working with the return address stack, because it doesn't store information about the IP's direction. This lets us save a few bytes because the IP will move in the same (horizontal) direction on both w and k.

The linearised code is this:

IY' *mRw..Y;m;.!z?~RZOk@

Let's go through it:

I       Read one line of input.
Y       Unzip. Separates the string into even and odd positions.
' *     Append a space to the odd half.
m       Truncate: discards characters from the longer of the two
        strings until they're the same length. So if the input
        length was even, appending a space will make the odd half
        longer and this discards the space again. Otherwise, the
        space just padded the odd half to the same length as the
        even half and this does nothing.
R       Reverse the odd half.
w       Push the current IP address to the return address stack.
        The purpose of this is to run the following section
        exactly twice.

          This first part splits the current line in half, based
          on an idea of Leo's:
  ..        Make two copies of the current half.
  Y         Unzip one of the copies. The actual strings are irrelevant
            but the important part is that the first string's length
            will be exactly half the original string's length (rounded up).
  ;         Discard the potentially shorter half.
  m         Truncate on the original string and its even half. This shortens
            the original string to the first half of its characters.
  ;         Discard the even half, because we only needed its length.
  .!        Store a copy of the first half on the tape.
  z         Drop. Use the first half to discard it from the original string.
            This gives us the the second (potentially shorter half).
  ?         Retrieve the first half from the tape.
  ~         Swap it so that the second half is on top.
          The string has now been split in half.
  R       Reverse the second half.
  Z       Zip. Interleave the two halves.
  O       Print the result with a trailing linefeed.

k       Pop an address from the return address stack and jump back there.
        The second time we reach this, the return address stack is empty,
        and this does nothing.
@       Terminate the program.

Jelly, 23 22 bytes

-1 byte thanks to Leo (bottom-left may be the padding)

LḂ⁶ẋ;µṚ,µm2œs2U0¦ż/µ€Y

A full program printing the result (the monadic link returns a list of lists of lists of characters).

Try it online! or see a test suite.

How?

LḂ⁶ẋ;µṚ,µm2œs2U0¦ż/µ€Y - Main link: list of characters
L                      - length
 Ḃ                     - modulo 2
  ⁶                    - literal space character
   ẋ                   - repeat
    ;@                 - concatenate (swap @rguments) (appends a space if the input's length is odd)
      µ                - monadic chain separation, call that s
       Ṛ               - reverse s
        ,              - pair with s
         µ         µ€  - for €ach:
          m2           -   modulo 2 slice (take every other character)
            œs2        -   split into two "equal" chunks (first half longer if odd)
               U0¦     -   upend index 0 (reverse the second chunk)
                   /   -   reduce by:
                  ż    -     zip
                     Y - join with newlines (well just the one in this case)
                       - implicit print (mushes the sublists together)