9
Introduction
Alice is a 2-d language by Martin Ender which has two different execution modes, cardinal and ordinal. When the instruction pointer passes through a mirror (either /
or \
), it switches from one mode to the other one.
In this challenge we will focus on ordinal mode, where commands operate on strings and the instruction pointer moves diagonally, bouncing against the edges of the code.
Simple programs operating only in ordinal mode can be written in a quite compact style, like in the following example:
/fbd/
@aec\
Here the IP starts in cardinal mode from the first cell going east, passes through the first mirror and starts moving diagonally and bouncing, executing commands a
, b
, and c
. It then encounters the north-east mirror which makes it go south towards the other mirror and then start bouncing back towards the west, encountering commands d
,e
,f
, and finally @
, which terminates the program.
This kind of structure is quite compact, but it's not easy to write and maintain (adding a single command might force us to reorder most of the code!), so I'd like you to help me with formatting.
The task
Given a sequence of commands, where each command is a single printable ASCII character, reorder them on two lines so that the first half of the sequence can be read starting from the first character of the second line and then moving always diagonally towards the right, while the second half can be read taking the remaining characters from right to left. Don't worry about mirrors and the termination symbol, I'll add them myself.
So, for example, given input abcdef
you should output
fbd
aec
In case the input is of odd length, you should add a single space (which is a noop in Alice) anywhere, as long as the sequence of commands encountered remains the same. You can also choose to output two lines differing in length by one character, in which case the shorter one is considered as having a single space at the end.
Rules
This is code-golf, the shortest answer, in bytes, wins!
- You may input/output via any of the default input/output methods
- Input consists of a single line of printable ASCII characters
- A single trailing newline is permitted in the output
- Some outputs of your program may not have a completely correct behavior when run as Alice programs (e.g. if the padding space is inserted inside a string literal). You don't have to concern yourself with these situations
- Standard loopholes are forbidden
Test cases
--Input
abcdef
--Output
fbd
aec
--Input
123
--Output
2
13
OR
31
2
OR
3
12
OR
32
1
--Input
O
--Output
O
OR
O
--Input
"Hello, World!"o
--Output
oH!lloo
""edlr,W
--Input
i.szR.szno
--Output
o.zz.
inssR
--Input
" ^^} .~[}.~~[}{~~{}[^^^^.""!}"r.h~;a*y'~i.*So
--Output
o *^i}'.*[;.h~r}}~"{.[^
"S .^~ y~a}~~.["{!~"}^^^
(Odd length, your solution may be different)
1I'll have to post another challenge for this new layout you came up with! :D Very nice, I think I'll start using it even when I don't use the return stack, it's easier to read both halves of the code from left to right – Leo – 2017-05-24T10:02:42.173