9
1
PPCG hasn't had enough of quines already...
Challenge:
Your task is to create a program "A0". When this program is run with no input, it outputs nothing. When this program is run with input, it outputs "A1". When "A1" is run with no input, it outputs "A0". When "A1" is run with input, it outputs "A2". Pretty much, "A(k)" will output "A(k-1)" when run with no input, and will output "A(k+1)" when run with input.
Details
I believe this challenge is simple enough; there are no other rules really. Every program must contain at least 1 byte, by the way. You may assume that the input will consist of only ASCII characters, and you may ignore whitespace if you want, but you may not specify a specific input. Output may be to either STDOUT or STDERR, but all of your programs must output to the same one. The other one may also contain text (so you may output to STDOUT and then exit with an error). Thanks to @Dennis for pointing that out.
All programs must be in the same language, and each program must be unique from the rest of them.
The score is equal to the length of program "A0". As this is a code-golf challenge, the lowest score wins!
I am sad to predict that most submissions will have A(k) and A(k+1) differing by a single character being added to a growing string :( – Sparr – 2017-02-24T00:06:44.930
@Sparr Unfortunately, that is probably going to be what happens. :( Oh well, I can't figure out how to make a clear rule against that. – HyperNeutrino – 2017-02-24T00:08:19.637
you can only output to one of the two I'm not dure if I'm interpreting this correctly. If we print the desired output to STDOUT, does STDERR have to be empty? Because it is udually allowed to exit with an error. – Dennis – 2017-02-24T01:20:31.020
Must all the programs be different? The question doesn't say that. – None – 2017-02-24T01:41:31.333
@Dennis Yes, that was my intention. Is that the case? I'm not too familiar with the rules here, so I guess I'll change the specs to follow standards. Thanks for pointing that out! – HyperNeutrino – 2017-02-24T01:42:13.873
@ais523 That is not a specification. However, it is impossible to write a valid solution where all programs are the same, because "A0" and "A1" behave differently when given no input; A0 prints nothing but A1 prints A0. So, in short, yes, but not because I said so, it's because it doesn't work otherwise. – HyperNeutrino – 2017-02-24T01:43:10.497
@ais523 I also clarified (which I forgot to do earlier) that all programs must be non-empty. So sorry if that messes up your solution, but that's a potential loophole that I forgot to specify. If you have a solution that exploits this loophole, go ahead and submit it, and I'll give it an upvote, but I won't consider it to be valid. – HyperNeutrino – 2017-02-24T01:47:32.823
@HyperNeutrino Please don't encourage invalid answers. Invalid answers should and will be deleted.
– Martin Ender – 2017-02-24T08:49:24.3074Also, may I suggest a somewhat more expressive title like "Bidirectional Quine Chain"? "super meta quine" doesn't say a whole lot beyond programs printing other programs and will make it harder to search for this challenge in the future. – Martin Ender – 2017-02-24T08:52:05.797
Are
Ai
andAj
required to be in the same language? – NonlinearFruit – 2017-02-27T20:49:18.403@MartinEnder I hope my most recent edit fixed that issue. – HyperNeutrino – 2017-02-28T02:43:07.530
@MartinEnder And also, thanks for the title suggestion; I've made the change. – HyperNeutrino – 2017-02-28T02:43:25.833
@NonlinearFruit Yes. I will clarify that in the question. Thanks! – HyperNeutrino – 2017-02-28T02:43:46.640
Is the chain supposed to continue indefinitely, i.e. there's an A(k) for all k >= 0? – DLosc – 2017-02-28T09:12:21.713
@DLosc The scoring used to be
length of program "A0" in bytes
but the most recent edit removed that... – NonlinearFruit – 2017-02-28T14:30:42.033@DLosc Added that back in. Thanks for noticing. – HyperNeutrino – 2017-02-28T16:01:39.210
Related – mbomb007 – 2017-02-28T16:15:04.820