This 128-language quine ouroboros (a program which outputs a program in another language, which outputs a program in yet another language, (125 languages later), which outputs the original program) is pretty impressive. But unfortunately, it has a static number of iterations.
Write a program which outputs a program (not necessarily in another language, but it can be), which outputs a program, which outputs a program, etc., which after n iterations, outputs the original program for the first time (i.e. no intermediate program should be the same as the original, because otherwise a quine which ignores its input would work), where n is a non-negative integer provided as input. The input can't be just a number in the original source code (e.g. putting x = <the value of n>
at the start of your program), it should be one of the following:
- Passed as a command-line argument
- Read from standard input
- Passed as an argument to a function, which returns/outputs the new program.
For intermediate stages in the ouroboros, your program can either be a fully-functioning program, or a function with no arguments, which, when called, will return/output the next one.
You may not read from the source file itself, or use any quine-like builtins (I don't think there are any which would do this, but there might be)
To be clear, if n = 0
, the program should output its own source code.
If n = 1
, the program should output a different program, which outputs the original source code.
And so on...
Fewest bytes wins!
Edit:
I should have written "For intermediate stages in the ouroboros, your program can either be a fully-functioning program with no input, or a function with no arguments". If your program outputs the next one in the chain, then waits for input, that's fine, but your program shouldn't need the original value of n.
getInput()
is used without any input provided. Or can we let's say input something random that's unused for later iterations, to prevent errors for thegetInput()
? A.k.a. is the current Python answer valid? \$\endgroup\$n
, output a program that is the "initial program" of an ouroboros quine ofn
iterations, and that our answer shouldn't count as one of then
iterations. Is this correct? \$\endgroup\$