This is a variant on the self-replicating program, defined here as a program that outputs its source (or a ). Below is an example of a self-replicating program in Python:

s = 's = %r\nprint(s%%s)'

When run from a file, this script should output itself.

Instead of a self-replicating program, I want you to write a mutating, replicating program. This is a program that outputs something similar to its source, but with a mutation. The mutated source must also be able to replicate, but it should change the functionality of the program in some way. Here is an example:

s = 's = %r\ns = s.replace(s[-17],str(int(s[-17])+222))\nprint(s%%s)'
s = s.replace(s[-17],str(int(s[-17])+222))

When this Python script is run, it outputs the following program:

s = 's = %r\ns = s.replace(s[-17],str(int(s[-17])+224224224))\nprint(s%%s)'
s = s.replace(s[-17],str(int(s[-17])+224224224))

If you repeat a number of times, you will see that it continues to mutate but remain functional.

Incorporating a raw dynamic environment variable in your code, like a comment with a timestamp, is boring. Don't do that.

Edit: For that matter, let's follow the standard quine rule of no input.

This is so the shortest in bytes wins.

Clarifications: I've been asked to clarify, but without much information I'm not sure what needs clarifying. Here's my best shot:

  • Each iteration should have source code that is different from the last.
  • The iteration must still run.
  • The iteration must still replicate according to the same rules.
  • Comments or strings can't be the only thing that changes. In dzaima's answer the operations on the string are duplicated, not just the contents of the string--so that is valid.
  • Each iteration must be runnable in the same language you started in.
  • \$\begingroup\$ Not sure if I should actually tag the question with quine or not, since the desired solutions are not technically quines. \$\endgroup\$ Apr 28, 2017 at 14:39
  • \$\begingroup\$ Possible duplicate \$\endgroup\$ Apr 28, 2017 at 14:52
  • \$\begingroup\$ @mathjunkie This is not a duplicate because that has the constraint that the program must cycle back to its original form. And also the restriction that there must be two programs at some point that share no characters in common. \$\endgroup\$ Apr 28, 2017 at 14:53
  • \$\begingroup\$ That other challenge might actually be harder than this one, given those constraints. \$\endgroup\$ Apr 28, 2017 at 16:43
  • \$\begingroup\$ @Draco18s It is in fact, but since it has no solution yet, it would probably be a good exercise to solve this easier problem first. \$\endgroup\$ Apr 28, 2017 at 16:45

4 Answers 4


Jelly, 4 bytes


Try it online!

(Equivalent to the 5-byte: “ṘȮ”Ṙ)

Exponentially spawns:


Since is a monadic atom which prints a Jelly representation of its input and then yields it's input, and Ȯ is a monadic atom which prints its input and yields it's input (neither printing any newlines), while “...” defines a list of characters. So each “ṘȮ”Ṙ prints “ṘȮ” and yields to the following Ȯ which prints ṘȮ and yields... a trailing Ȯ finally yields for the programs return value, which is implicitly printed, so the pattern will continue until resources no longer suffice.


SOGL, 9 bytes



:+q$o”     push that string
      q    output it in a new line without popping
       $   push "”"
        o  output that
           implicitly output the original string (in a new line)

The iterations go as (one per line)


and the next one is 31424 characters long.

The first iteration is

:+q$o”        push that string
      ¶       no-op
       :+     add the string to itself
         q    output it in a newline without popping
          $o  append "”"

and the next:

:+q$o:+q$o”             push that string
           ¶            no-op
            :+          add the string to itself
              q         output it in a newline without popping
               $o       append "”"
                 :+q$o  the same

This should never break from what I can see (well except hitting javas string length limit or something), because only the last string is used and the rest of the code is just multiply, output.

note: newlines and are completely interchangeable in SOGL.

  • \$\begingroup\$ Looks good. Unless you know of a way to run online, I'll have to test when I get home. \$\endgroup\$ Apr 28, 2017 at 17:31
  • \$\begingroup\$ No way of running SOGL online currently, sorry \$\endgroup\$
    – dzaima
    Apr 28, 2017 at 17:32

Python 2, 33 bytes

_='_=%r;print _%%_*2;';print _%_;


Doubles in size. (This is technically only true from the third iteration onwards) Based on this Quine. Similar to my Pyth answer.


_='_=%r;print _%%_*2;';print _%_;

_='_=%r;print _%%_*2;';print _%_*2;

_='_=%r;print _%%_*2;';print _%_*2;_='_=%r;print _%%_*2;';print _%_*2;

_='_=%r;print _%%_*2;';print _%_*2;_='_=%r;print _%%_*2;';print _%_*2;
_='_=%r;print _%%_*2;';print _%_*2;_='_=%r;print _%%_*2;';print _%_*2;

_='_=%r;print _%%_*2;';print _%_*2;_='_=%r;print _%%_*2;';print _%_*2;
_='_=%r;print _%%_*2;';print _%_*2;_='_=%r;print _%%_*2;';print _%_*2;
_='_=%r;print _%%_*2;';print _%_*2;_='_=%r;print _%%_*2;';print _%_*2;
_='_=%r;print _%%_*2;';print _%_*2;_='_=%r;print _%%_*2;';print _%_*2;

Pyth, 11 bytes


Try it

Try it online

Gets exponentially longer. Based on this Pyth Quine.

first 4 iterations



     "jN*4[                 # The String "jN*4["
    ]                       # Make it into a list with one element
  *4                        # Quadruple that list
jN                          # join on quote (N='"')

                 "jN*4[     # The string "jN*4["
                [           # List with the string: ["jN*4["]
              *4            # Quadruple that list
            jN              # Join on quote
     "jN*4["                # The string "jN*4["
    [                       # Put both strings into a list
  *4                        # Quadruple that list
jN                          # join on quote (N='"')

(I could probably prove this rigoriosly using induction, but I'm not in the mood for that.) This should (theoretically always work because) it's just even multiples of jN*4[". Every second occurence of that sequence of characters is interpreted as a string because of the " of the previous one. The [ of the previous one then puts that string into a list together with what the next one produces. Then that list is repeated four times and joined to string with ".

  • \$\begingroup\$ In your explanation you say *2 instead of *4. \$\endgroup\$ Apr 29, 2017 at 9:23
  • \$\begingroup\$ @EriktheOutgolfer Fixed, thanks! \$\endgroup\$
    – KarlKastor
    Apr 29, 2017 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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