There's an old story about a stonecutter who was never satisfied with what he was. He wished he could become the sun, and so he was. Blocked by the clouds, he wished to be - and became - a cloud. When the wind blew, he wished himself into being the wind. Stopped by the mountain, he wished to be a mountain, and thus became one. Soon, however, he was being hacked at by a stonecutter, and wished to be a stonecutter.
Similarly, your task is to write a program which is never satisfied with the language it is in. Your program must output a set of regex replacements to turn it into a different language. And so on.
- Write a program in a language of your choice.
- The program should output a series of at least two segments. A segment is a bunch of text, separated by semicolons. However, if a semicolon is contained within a regex, such that breaking it up there will result in invalid syntax, it does not separate segments. See the example.
- The first segment is a regex pattern to find, and the second segment is the replacement pattern. The third is another "find" pattern, and the fourth is a "replace" pattern, and so on.
- Apply the regex patterns to the program. Replace the pattern on the first segment with one on the second; replace the third pattern with the one on the fourth, and so on.
- The result should be a program in a different language, which, itself, follows rules 2 to 4.
- The languages used must form an infinite, repeating cycle.
- For example, Python -> PHP -> C++ -> Python -> PHP -> C++ -> Python -> ...
- Your score is the period of the cycle. Ties are broken by shortest initial code length.
- In the above example, the score is three.
- In each iteration of the cycle, no language may be used more than once.
- For rules 5 and 7, compatible languages (C and C++) and different versions of the same language (Python 2 and Python 3) are considered the same.
- The programs themselves do not need to repeat.
- In the above example, the first and fourth programs may be different.
- Any version of regex is acceptable, but the same must be used for all the programs.
- The total output for each program may not exceed 100 characters.
- Each output must contain instructions to actually change the program. That is, no two consecutive programs in the cycle may be the same.
Python -> Ruby -> Python -> ...
The segments are:
FIND ; REPLACE uts ; Z rint ; uts Z(?=;Z ; rint (breaking the first segment in two would result in invalid syntax)
Applying the regex replacements, in order, gives us:
print "Z;Z;rint;Z;Z(?=;Z);rint" # replace each "uts" with "Z" puts "Z;Z;uts;Z;Z(?=;Z);uts" # replace each "rint" with "uts" puts "rint;Z;uts;rint;Z(?=;Z);uts" # replace each "Z" followed by ";Z" with "rint"
Running the last line gives us the instructions to turn this back into Python code.