10
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.
Related, related. – Kevin Cruijssen – 2019-07-03T11:56:08.190
Can we 1 index n? So n = 1 means print source code, n = 2 means print code which will print source code etc. – Expired Data – 2019-07-03T12:46:14.510
1Will the iteration versions still have the initial input? So let's say my first input is 3, and I run the program it output. Will there still be an input 3, or no input at all? If there is no input, I guess we need to handle that in case something like
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? – Kevin Cruijssen – 2019-07-03T13:11:02.707I suspect that what we're asked to do is, given an integer
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? – Erik the Outgolfer – 2019-07-03T14:12:12.010@KevinCruijssen I probably should have been more clear about that. The intermediate stages can't have input in any form. I guess if the program outputs the next one and then waits for input, that would be fine. – Leo Tenenbaum – 2019-07-03T22:37:03.653
@EriktheOutgolfer Yes... – Leo Tenenbaum – 2019-07-04T06:07:16.493