# Slow growing Quine

Make a Quine.

Seems easy right? Well this quine must output itself plus its first character, which then outputs itself plus its second character, and so on.

This way the quine should in several generations output two copies.

Example: Lets your code be x. Running it should output x + x[:1]. Running the resulting program should output x + x[:2] and so on...

If your code was foobar, running this should output foobarf. Running this should output foobarfo. And so on and so forth following this pattern:

foobar
foobarf
foobarfo
foobarfoo
foobarfoob
foobarfooba
foobarfoobar
foobarfoobarf


Your Program must be longer than 2 Bytes and must output only ONE extra character of its own code each iteration.

• I suspect that this challenge is impossible in most languages, given that reading source code is forbidden by default. – Ørjan Johansen May 4 '17 at 18:12
• @ØrjanJohansen and then Dennis shows up – Rod May 4 '17 at 18:13
• @Rod Well I didn't say all, it's just that many/most languages have no obvious way to add arbitrary fragments of code to the end in such a way that (1) it doesn't give a syntax error (2) the program can detect the change. – Ørjan Johansen May 4 '17 at 18:23
• Since this is a very unusual quine, are the usual quine loopholes still disallowed? – Draconis May 4 '17 at 20:14

# Zsh, 110108 100 bytes

a=<&0<<''<<<t;b=${a:0:50};printf$b$b${a:0:-50}
a=<&0<<''<<<t;b=${a:0:50};printf$b$b${a:0:-50}



Try it online!

So it is possible.

### Explanation

a=<&0<<''<<<t;       # Set A to everything following this line, until eof or
#   an empty line (which never happens before eof) encountered.
# A "t" is appended to prevent automatic trimming of newlines.
b=${a:0:50}; # Set B to the first line. printf$b$b${a:0:-50}  # Print two copies of B and
#   A with 50 trailing characters removed.

• – jimmy23013 May 4 '17 at 19:49

# R, 289 bytes

s<-c("s<-", "i=get0('i',ifnotfound=0)+1;p=paste0(s,substr(get0('p',ifnotfound=s),1,i),collapse='');cat(s[1]);dput(s);cat(paste0(s[2],substr(p,1,i)))#")
i=get0('i',ifnotfound=0)+1;p=paste0(s,substr(get0('p',ifnotfound=s),1,i),collapse='');cat(s[1]);dput(s);cat(paste0(s[2],substr(p,1,i)))#


credit to this quine for inspiration. Only works if run in the same R environment as the previous quine is run.

• an explanation will be forthcoming...I haven't tested it 288 times yet, but I'm fairly convinced it's correct – Giuseppe May 4 '17 at 19:14
• It provably should be 289 bytes since the quine adds a newline character there but anyway its great you've solved it! – IQuick 143 May 4 '17 at 19:17
• ah, you're right, stupid cat adding newlines. – Giuseppe May 4 '17 at 19:18
• But is this a full program? Are the generated code full programs? – jimmy23013 May 4 '17 at 19:48
• @jimmy23013 As far as I can tell, this answer and the generated code are full programs. There is no main or any other mandatory structure like that in R. Besides, the question doesn't explicitly ask for a full program, so a function or similar would do. – Steadybox May 4 '17 at 20:11

## Alice, 29 bytes

4P.a+80pa2*&wdt,kd&w74*,.ok@


Try it online!

The unprintable character is 0x18.

### Explanation

The trouble with the usual "-based Fungeoid quines is that if we repeat the entire source code, then we also get additional " and the string no longer covers the entire source code. I assume that's why the existing answer uses the cheat-y g approach instead.

This answer does use the "-based approach, but instead of including a " in the source, we write it into the program at runtime. That way, there will only ever be one " regardless of how often the program is repeated (because we only write it to one specific coordinate, independently of program size).

The general idea is then that we create a representation of the whole source code on the stack, but only cycle through the first 29 of the characters (i.e. the program length) with the length of the loop determined by the size of the code. Therefore, we can actually append arbitrary characters (except linefeeds) after @ and the result will always be a cyclic repetition of the core program, one character longer than the source.

4P   Push 4! = 24. This is the code point of the unprintable, which we're
using as a placeholder for the quote.
.a+  Duplicate it and add 10, to get 34 = '"'.
80p  Write '"' to cell (8,0), i.e. where the first unprintable is.
    Placeholder, becomes " by the time we get here, and pushes the code
points of the entire program to the stack. However, since we're already
a good bit into the program, the order will be messed up: the bottom
of the stack starts at the 24 (the unprintable) followed by all
characters after it (including those from extraneous repetitions). Then
on top we have the characters that come in front of the ".
So if the initial program has structure AB, then any valid program has
the form ABC (where C is a cyclic repetition of the initial program),
and the stack ends up holding BCA. We don't care about C, except to
determine how big the program is. So the first thing we need to do is
bring B to the top, so that we've got the initial program on top of
the stack:
a2*  Push 10*2 = 20.
&w   Run the following section 21 times, which is the length of B.

dt,  Pull up the value at the bottom of the stack.

k    End of loop.
d&w  Run the following section D+1 times, where D is the length of ABC.

74*  Push 28, one less than the number of characters in AB.
,    Pull up the 29th stack element, which is the next character to print.
.o   Print a copy of that character.

k    End of loop.
@    Terminate the program.

• Great solution. I like the explanation. – IQuick 143 Mar 21 '18 at 14:11

# Perl 5, 83 bytes (including final newline)

$_=q($/=$;;$_="\$_=q($_);eval
__END__
".<DATA>;print$_,/(.).{82}\z/s);eval __END__  Try it online! The good ol' __DATA__ token makes it easy to append an arbitrary string to any Perl program, which the main program can then access via the <DATA> file handle (and actually using __END__, which does the same thing for backwards compatibility, instead of __DATA__ saves two extra bytes). Note that this program does not read its own source code, but only the extra input data appended to its source after the __END__ token. In effect, the __END__ token and everything after it functions kind of like a string literal terminated by the end of the input. Also note that, in order to meet the spec exactly, this program must end in a newline. If it does not, the newline actually gets automatically appended after the second __END__ anyway, but then the first iteration output won't be precisely equal to the code plus its first byte any more. # Befunge-98, 30 bytes 0>:#;0g:840#;+*#1-#,_$a3*%0g,@


Try it online!

My try using Befunge-98 which uses a space terminated quine which also counts how many characters have been outputed. Does however use the g command.

• You might want to mention in the first line that it's non-competing/cheating, just to discourage any downvotes it might otherwise receive. – quintopia May 5 '17 at 22:38

# PHP, 146 bytes

ob_start(function($s){return($u=substr($s,0,73)).$u.substr($s,0,-72);})?>ob_start(function($s){return($u=substr($s,0,73)).$u.substr($s,0,-72);})?>


It should be run using -r in command line.

• Doesn't seem to work when I Try it online!, it's just an ordinary quine. – Ørjan Johansen May 6 '17 at 10:55
• @ØrjanJohansen You should run it with php -r 'command'. – jimmy23013 May 6 '17 at 11:01
• Gah, cannot get it to work. TIO seems to just ignore the -r arguments. – Ørjan Johansen May 6 '17 at 11:54
• @ØrjanJohansen This is how you should test it. – jimmy23013 Mar 17 '18 at 15:07
• Aha. I must have misunderstood something back then. Now I managed to get it to work with PHP as the language setting, too. – Ørjan Johansen Mar 17 '18 at 15:20

# Runic Enchantments, 61 bytes

803X4+kw.'.q}͍}͍}͍}͍}͍}͍}͍}͍}͍::l͍5X-:}-\$:l͍{-1--@


Try it online!

Uses a similar approach as the Alice answer: reflectively writes the string " command into the code so that there Is Only One. There rest is a lot of string and stack manipulation to recover the original program, how many extra bytes are needed, and print the necessary hunks.

The }͍ sequence rotates the in-memory string representation around so that the 803X4+kw appears at the beginning instead of at the end, due to the position of the " and there isn't an easier way of handling this operation without having to compute a lot of awkward numbers.

While the original program is 61 bytes its string-length is only 50, which is easy to construct as 5X and it was only coincidence that this didn't need to be padded out after containing all necessary functionality (e.g. a length 49 program would be easier to encode as 50 with one byte of padding than to encode a literal 49, while 51 would be encoded as 5X3+ or 53, having to account for its own extra bytes).