-X
Try it online!
Try the reverse!
Explanation
Turns out this is actually a lot easier than the previous challenge in Stack Cats. The full program (after applying -m
) here is -X-
. X
is used to swap the stacks left and right of the tape head, i.e. it doesn't affect the initial stack at all, so we can ignore it. But then the program is effectively just --
(negate the top of the stack twice), which does nothing.
For the inverse program, applying -m
gives X-X
. Again, X
does nothing, so the program is effectively just -
, which negates the top of the stack.
The only other 2-byte solution is -=
, but it's virtually the same. The only difference is that =
swaps only the tops of the adjacent stacks, not the entire stacks.
But again, using -m
feels a bit like cheating, so below is a solution that uses a fully mirrored program.
:I<->I:
Try it online!
Try the reverse!
Explanation
The considerations from the previous answer still apply: any valid solution needs to use the paired characters and I
. The six possible solutions (included in the TIO link) are all virtually the same. -
and _
are equivalent in this program, and :
can be replaced by |
or T
(which do the same for non-zero inputs and coincidentally also work for zero inputs). I've just picked this one to explain because it's easiest.
So remember that the initial stack holds the input on top of a -1
(on top of infinitely many zeros) whereas all the other stacks along the tape only hold zeros. Stack Cats also has the property that any even-length program does nothing (provided it terminates, but we can't use loops for this challenge anyway). The same is then obviously true for any odd-length program whose centre character does nothing... let's see:
: Swap the input with the -1 below.
I Move the -1 one stack to the left and turn it into +1.
< Move another stack left (without taking the value).
- Negate the zero on top of that stack (i.e. do nothing).
Therefore, the second half of the program exactly undoes the first half and we end up with the input on top of a -1
again.
The inverse program is :I>-<I:
. Let's see how that changes things:
: Swap the input with the -1 below.
I Move the -1 one stack to the left and turn it into +1.
> Move one stack right, i.e. back onto the initial stack which still holds the input.
- Negate the input.
< Move back to the left where we've parked the 1.
I Move that 1 back onto the initial stack and turn it back into a -1.
: Swap the -1 below the negated input to act as an EOF marker.