10
\$\begingroup\$

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.

\$\endgroup\$
7
  • 5
    \$\begingroup\$ 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. \$\endgroup\$ Oct 14 at 6:04
  • \$\begingroup\$ @AndersKaseorg there is no number bigger than infinity :) \$\endgroup\$ Oct 14 at 6:05
  • 5
    \$\begingroup\$ 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.) \$\endgroup\$ Oct 14 at 6:13
  • \$\begingroup\$ @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. \$\endgroup\$ Oct 14 at 6:22
  • 2
    \$\begingroup\$ 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 \$\endgroup\$ Oct 14 at 6:27
8
\$\begingroup\$

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\$.

\$\endgroup\$
4
\$\begingroup\$

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

\$\endgroup\$
2
  • 2
    \$\begingroup\$ You can change console.log to alert \$\endgroup\$
    – pxeger
    Oct 14 at 19:11
  • 1
    \$\begingroup\$ 53 bytes using recursion instead of a for loop \$\endgroup\$
    – Jo King
    Oct 15 at 3:17
3
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 46 bytes with recursion \$\endgroup\$
    – Jo King
    Oct 15 at 4:12
3
\$\begingroup\$

Vyxal D, 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
\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$

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.