0

A rotation of a string is made by splitting a string into two pieces and reversing their order, for example

"world! Hello,"
is a rotation of
"Hello, world!"
. It is possible to create programs that can be rotated to form a different, but still valid program. Consider this example in python:

print ")import sys; sys.stdout.write("

It can be rotated to form

import sys; sys.stdout.write("print ")

Which is itself a valid python program.

Your challenge is to write a program that outputs a rotation of itself, which when run will output the original program. Bonus points to any entry with a cycle length greater than two!

This is code golf, the exact scoring will be: (length of code)/(cycle length – 1).

EDIT: We have a winner (unless someone else is able to beat a score of 4)! I’d still be very interested to see any other solutions, whether they’re contenders or not.

Asked question