Write a program or function which, when run, outputs another program or function which is valid in the same language as the original program, and which itself will output another program or function that has the same properties. You must at one point end up back to your initial program or function.


Suppose you write program A. When run, it outputs program B. When you run B, it outputs program C. When you run C, it outputs program A, thus completing the circle. A, B and C are all valid in the same language and are all different by at least one character.


Your score is calculated as <Number of bytes of the initial program>/<number of iterations to get back to the initial program>

For instance, with the programs A, B and C in the previous example, the number of iterations is 3 (you have to run 3 times to get back to A) and the number of bytes is the number of bytes of A.

This incentivize both golfing your initial code, and having an initial program that leads to a longer chain.

The smallest score wins

  • \$\begingroup\$ This incentivizes long programs with long cycles too much. \$\endgroup\$
    – lirtosiast
    Commented Jul 4, 2015 at 0:00
  • 2
    \$\begingroup\$ How about bytes/sqrt(log(cyclelength)), or even bytes/log(log(cyclelength))? \$\endgroup\$
    – lirtosiast
    Commented Jul 4, 2015 at 0:07
  • 3
    \$\begingroup\$ @ThomasKwa: Yup, we need a new scoring algorithm. \$\endgroup\$
    – Dennis
    Commented Jul 4, 2015 at 0:13
  • 2
    \$\begingroup\$ Could you explain the title? I can't see the connection with permutation groups. \$\endgroup\$ Commented Jul 4, 2015 at 7:03
  • 1
    \$\begingroup\$ So why not use the standard term: ouroboros? Does that not sound cool enough? \$\endgroup\$ Commented Jul 4, 2015 at 9:41

3 Answers 3


CJam, score → 0


Try it online in the CJam interpreter.

The actual score of this program is obviously positive, but 1e9 can be replaced with 1e99, 1e999, 1e9999, 1e99999, etc.

The numerator of the score grows much slower than the denominator.

How it works

{          }     e# Define a block:
 )               e#   Increment the integer on the stack.
  1e9%           e#   Take the incremented integer modulo 1,000,000,000.
      "X$~"      e#   Push that string.
            0    e# Push 0.
             X$~ e# Copy the block and execute the copy.

                 e# The stack now holds the block, the modified integer and
                 e# the string "X$~", all of which CJam prints before exiting.

Executing the code prints {)1e9%"X$~"}1X$~ which, when executed, prints {)1e9%"X$~"}2X$~, etc.

After reaching {)1e9%"X$~"}999999999X$~, one more execution yields the original code.

  • 4
    \$\begingroup\$ Well that escalated quickly... \$\endgroup\$
    – Fatalize
    Commented Jul 4, 2015 at 0:06
  • \$\begingroup\$ Now do you see how easy it is to make a long cycle? \$\endgroup\$
    – lirtosiast
    Commented Jul 4, 2015 at 0:09
  • \$\begingroup\$ @Fatalize If I make something that approaches $0$ faster, do I win. Also, Dennis, how fast does yours approach $0$, asymptotically? \$\endgroup\$ Commented Jan 24, 2016 at 4:22
  • \$\begingroup\$ @PyRulez By simply replacing the exponent in 1e9 with a larger number, the score of a program of length L is L / 10^(L - 15) for L > 15. There are unlimited ways to reduce the score faster though. \$\endgroup\$
    – Dennis
    Commented Jan 24, 2016 at 4:30

Javascript ES6, 68/1.8e16 (basically 0)


Based on my Bling Quine framework:


Here's the output sequence starting from $(0):


Underload, score of 0 in the limit


Adding another :* to the sequence of :* will add two bytes to the program, and double the period of the quine. Thus, the score can be made arbitrarily small by adding more copies.

Try it online!

This basically uses the Underload universal quine constructor (a(:^)*fS):^, which is capable of producing a program whose output is any function f of the original source code. In this case, the function in question produces a string that outputs its argument in the most naive way (by escaping it and adding a print statement; escape is a, add a print statement is (S)*); and we run the function in a loop (via ^) a power of 2 times. (2 to the power of n can be written in Underload by using n repeats of :*.) The result is output like


which produces, when run,


and so on until the original program is reached.


Not the answer you're looking for? Browse other questions tagged or ask your own question.