# Write a mutating, replicating program

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)'
print(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))
print(s%s)


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))
print(s%s)


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.
• Not sure if I should actually tag the question with quine or not, since the desired solutions are not technically quines. – called2voyage Apr 28 '17 at 14:39
• Possible duplicate – math junkie Apr 28 '17 at 14:52
• @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. – called2voyage Apr 28 '17 at 14:53
• That other challenge might actually be harder than this one, given those constraints. – Draco18s no longer trusts SE Apr 28 '17 at 16:43
• @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. – called2voyage Apr 28 '17 at 16:45

# 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”q$o


Explanation:

:+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)

:+q$o”¶:+q$o
:+q$o:+q$o”¶:+q$o:+q$o
:+q$o:+q$o:+q$o:+q$o”¶:+q$o:+q$o:+q$o:+q$o:+q$o:+q$o:+q$o:+q$o”¶:+q$o:+q$o:+q$o:+q$o:+q$o:+q$o:+q$o:+q$o


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.

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

# Python 2, 33 bytes

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


Ideone

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

### iterations

_='_=%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

jN*2]"jN*4[


Try it

Try it online

Gets exponentially longer. Based on this Pyth Quine.

## first 4 iterations

jN*2]"jN*4[
jN*4["jN*4[
jN*4["jN*4["jN*4["jN*4[
jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4["jN*4[


## Explanation

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

jN*4["jN*4["jN*4["jN*4[
"jN*4[     # The string "jN*4["
[           # List with the string: ["jN*4["]

(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 ".
• In your explanation you say *2 instead of *4. – Erik the Outgolfer Apr 29 '17 at 9:23