# Iterative Quine

Create a program which prints itself, followed by an additional program. This additional program should print the first program, itself, and then a third program. This continues until the nth program, which prints every program in order up to itself, but fails to print a successor.

All programs output by your code should be delimited in the same way across all iterations.

## Example:

Program 1

Print(Me,MyEvilTwin)


Prints

Print(Me,MyEvilTwin)

Print(Me,MyEvilTwin,MyEvilTwin'sEvilTwin)


The generated program 2

Print(Me,MyEvilTwin,MyEvilTwin'sEvilTwin)


Prints

Print(Me,MyEvilTwin)

Print(Me,MyEvilTwin,MyEvilTwin'sEvilTwin)

Print(Me,MyEvilTwin,MyEvilTwin'sEvilTwin), And How!


The final generated program 3,

Print(Me,MyEvilTwin,MyEvilTwin'sEvilTwin), And How!


Prints

Print(Me,MyEvilTwin)

Print(Me,MyEvilTwin,MyEvilTwin'sEvilTwin)

Print(Me,MyEvilTwin,MyEvilTwin'sEvilTwin), And How!


Which fails to include a 4th program, making this 3 iterations.

### Scoring

Your score is the number of iterations your program achieves before failing to print a successor. If no iteration of your program fails to print a successor, your score is infinity. For programs with the same number of iterations, shortest code wins.

• There’s no upper bound to how many programs can be chained in this way, so this is going to degenerate into a “pick the largest number” competition. Commented Oct 14, 2021 at 6:04
• @AndersKaseorg there is no number bigger than infinity :) Commented Oct 14, 2021 at 6:05
• Your rules seem to require that there must be an nth program where the chain ends. If you mean to accept an infinite chain without an end, you should clarify that in the rules. (And then there’s no real reason to allow a finite chain, since an infinite chain is simpler to write anyway.) Commented Oct 14, 2021 at 6:13
• @Anders Kaseorg Should I enforce an infinite chain and switch this to code golf then? This is my first challenge, so I'm hesitant to do that on a whim after getting approval for this version. Commented Oct 14, 2021 at 6:22
• Ah, too late anyway. a finite answer has rolled in and i'd hate to disqualify. All things considered, i think it will be O.K... i will try not to worry about this as i am going to bed. good luck everyone Commented Oct 14, 2021 at 6:27

# Stacked, $$\N\$$ iterations

1:>:#',N take[1 + tostr ':>:#'',N take' + f tostr ':@f map' + + out]:@f map



Try it online!

$$\N\$$ appears twice in the code. Linked is the example for $$\N=9999\$$, but this theoretically works for any number $$\N\$$. The only change from each iteration is the number at the beginning, which is incremented with each iteration. We map a quine writing function over the range K:>, that is, the numbers from 0 to K-1 inclusive.

The length of the initial code is $$\74+2D\$$, where $$\D\$$ is the number of digits in the chosen $$\N\$$; that is, $$\76+2\lfloor\log_{10} N\rfloor\$$. Again for the example $$\N=9999\$$, the code length is 82.

Better solutions will either decrease the boilerplate or the number of instances of $$\N\$$.

# VyxalD, Infinite score, 25 bytes

:L$ȧ$17-ʁ꘍(nq\:Ė\+,:Ė


Try it Online!

While creating this, I discovered that Vyxal is not very good at most things involving eval. It adds a space before the last backtick each time.

Note: The D flag is to allow non-ASCII characters in strings, and is necessary for this to work.

                     :Ė # Execute using self as argument...
:L                       # Duplicate and get length
$ȧ$                    # Remove whitespace from the other copy
17-ʁ                # 0...n-17
꘍               # (For each of that range) append that many spaces to the string
(n             # Map... (Proper map is buggy)
q            # Uneval
\:Ė\+     # Append ':Ė' to make quinish
,    # Print


# ECMAScript 6, Infinite score, 58 bytes

($=n=>{for(i=0;i<n+2;)console.log(($=${$})(${i++}))})(0)  Try online Based on this quine: https://twitter.com/cowboy/status/232587756486938624, I only added a counter and switched it to ECMAScript 6 • You can change console.log to alert Commented Oct 14, 2021 at 19:11 • 53 bytes using recursion instead of a for loop – Jo King Commented Oct 15, 2021 at 3:17 • Jo King, the second iteration crashes with a TypeError, when you add line 2 to the code Commented Nov 18, 2021 at 0:28 # Pari/GP, Infinite score, 47 bytes PARI/GP uses arbitrary-precision integers by default. (f=(n)->for(i=0,n+1,print("(f="f")("i")")))(0)  Try it online! • 46 bytes with recursion – Jo King Commented Oct 15, 2021 at 4:12 # R, infinite score, 105 bytes 1 ->x;while(F<=x)cat(F<-F+1,sprintf(a<-"->x;while(F<=x)cat(F<-F+1,sprintf(a<-%s,dQuote(a))) ",dQuote(a)))  Try it online! Proper Quine that encodes itself and does not access its own source code. Outputted programs are delimited by a newline character (which also occurs once in the program itself). Add 8 bytes to delimit output with a double newline, which does not occur in the program itself. # Python 2, infinite score, 48 bytes s="c=2;print's=%r;exec s*'%s,c;c+=1;c";exec s* 2  Try it online! # Python 3, infinite score, 53 bytes s="c=2;print(f's=%r;exec(s*{c})'%s);c+=1;c";exec(s*2)  Try it online! ## Ruby, infinite, 59 bytes Updated: eval$a=%q[2.times{|i|puts"eval$a=%q[#{i+2}#{$a[-46..]}]"}]


Previous (66 bytes):

eval$a=%q[2.times{|i|puts"eval$a=%q[#{$a.sub /^\d+/,"#{i+2}"}]"}]  • Welcome to Code Golf, and nice first answer! Make sure to check out our tips for golfing in Ruby to see if there are any ways you can shorten this. Commented Nov 17, 2021 at 21:59 • Thank you @AaroneousMiller! Awesome thread! Gave it another shot and saved 7 bytes. Commented Nov 17, 2021 at 22:56 # Julia 1.0, infinite score, 69 bytes (c=1;a=:(println.("(c=$(i);a=:(\$(a)))|>eval" for i = 1:c + 1)))|>eval


Try it online!