The basic idea is to write a program that twists itself, and the twisted version untwists itself. The first program will just be the twisting algorithm described here, and when given its own source code as input, outputs a program that reverses the twisting algorithm.
How strings are twisted
The twisting algorithm is very simple. Each column is shifted down by its index (col 0 moves down 0, col 1 moves 1, ...). The column shift wraps to the top. It kinda looks like this:
a
ba
cba
----
cba
cb
c
With everything under the line wrapping to the top. Real example:
Original:
\\\\\\\\\\\\
............
............
............
Twisted:
\...\...\...
.\...\...\..
..\...\...\.
...\...\...\
(Further examples are here)
Input
Input is either an array of strings, or a multi-line string. All lines have the same length.
Output
The (un)twisted string, multi-line output to std-out (or closest alternative).
Example
I'm not quite sure what this is written in but oh well ;)
Twisting:
magic TwistingAlgo
magic ntwistingAlgo
magicU twistingAlgo
Untwisting:
magic twistingAlgo
magicUnTwistingAlgo
magic twistingAlgo
Other notes
- Your first and second program must be in the same language.
- The programs must work for any input, not just itself.
- Your program must have at least 2 rows and 2 columns.