|>I|
Try it online!
Try it reversed!
This works for any inputs that don't contain null bytes.
Explanation
Wow, I've reached the point where I'm writing these by hand...
The full program is |>I|I<|
.
| Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
> Move one stack over to the right (which only contains zeros).
I Does nothing on zero.
| Does nothing on zero.
I Does nothing on zero.
< Move back to the initial stack.
| Reverse the input once more.
As in the solution to the previous challenge, since the centre command |
does nothing, so does the entire program.
The reversed program is then |I>|<I|
.
| Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
I Move the -1 one stack to the left and turn it into a +1.
> Move back to the initial stack.
| Reverse it again, but this time without the EOF marker.
< Move back to the left.
I Move the +1 back onto the initial stack and turn it into a -1 again.
| Reverse the entire stack. We now have the -1 as an EOF marker again at the bottom
and the rest of the stack has been reversed three times, i.e. one net reversal.
Interestingly, if we use this reversing program without -m
we still get a working solution this time, so the only additional bytes incurred by omitting -m
are those we get from mirroring the code.
|I<|>I|
Try it online!
Try it reversed!
Explanation
The reversed version of this program is |I>|<I|
, the same as above so we can ignore that. But the non-reversed version differs. Since the <>
now point the other way, the centre command ends up doing nothing, so the program becomes a cat:
| Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
I Move the -1 one stack to the left and turn it into a +1.
< Move another stack to the left, which contains only zeros.
| Does nothing on zero.
And thus, >I|
exactly undo the first half of the program.