7
\$\begingroup\$

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

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.

\$\endgroup\$
2
\$\begingroup\$

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.

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

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;
\$\endgroup\$
2
\$\begingroup\$

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
  *4                        # Quadruple that list
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["]
              *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 ".

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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