9
1
As we know, a quine is a program that outputs its own source code. However, it's also possible to write a program that outputs another, different program, that outputs the first program again. For example, the Python 2 program
x = '''x = {}
print 'print '+'"'*3+x.format("'"*3+x+"'"*3)+'"'*3'''
print 'print '+'"'*3+x.format("'"*3+x+"'"*3)+'"'*3
will, when run, output the following text:
print """x = '''x = {}
print 'print '+'"'*3+x.format("'"*3+x+"'"*3)+'"'*3'''
print 'print '+'"'*3+x.format("'"*3+x+"'"*3)+'"'*3"""
When run as a Python program, this will output the original code again. This is called an iterating quine. Because you have to run it twice to get the original code back, we say it has period 2. But of course, much higher periods are possible.
Your challenge is to write an iterating quine with as long a period as you can, in 100 bytes or less, in the language of your choice. (Note that my example above doesn't fit this spec, as it's 119 bytes, including the trailing newline.)
Please note the following rules and clarifications:
- The usual quine rules apply, i.e. your program can't use language features that would let it access its own source code directly.
- The iterated outputs have to eventually loop back to exactly your original code, and you have to include a demonstration or proof that it will.
- You must also include an explanation of why the cycle is as long as you say it is. This doesn't have to be at the level of a mathematical proof, but it should be convincing to someone familiar with your language. (This rule is here because I expect some of the answers to involve very, very large numbers.)
- It's fine to say something like "at least 1,000,000 iterations" rather than giving the exact number, as long as you can prove that it is at least that long. In this case, your score would be 1,000,000. Otherwise, your score is the period of your quine.
- The 100 byte limit only applies to your initial program - the programs it outputs can be longer, though of course they'll eventually have to get back down to 100 bytes in order to output your original code.
- You can assume your machine has infinite RAM and infinite runtime, but you can't assume unlimited precision data types (such as integers) if your language doesn't have them. You can assume there is no limit to the length of input your parser can handle.
- The highest score wins.
Please note: there is an existing challenge called Quit Whining; Start Quining that also involves iterating quines. However, aside from being based on the same concept, these are completely different types of challenge. The other one is straight up code golf, whereas this one is (intentionally!) really a busy beaver problem in disguise. The techniques needed to produce a good answer to this question are likely to be very different from what's needed to answer the other question, and this is very much by design.
1@LeakyNun I don't know if it was you or a mod that deleted your answer, but perhaps if I explain what was wrong with it you will understand why this isn't a duplicate. This question specifies a 100 byte limit on the source length, so you actually can't go "as high as you want" using that method. That's the whole point of this question. To answer it, what you would have to do is post the longest version that fits into 100 characters, and say what its period is. What you posted would be a good first attempt but is very unlikely to be the winner. – Nathaniel – 2016-08-27T09:55:55.363
The other challenge also has an additional level of indirection in that the first program isn't part of the cycle and it actually takes the iteration length as a parameter. That said I'm not 100% sure there isn't a better dupe target. I'll need to have a look later. – Martin Ender – 2016-08-27T10:07:49.320
@Nathaniel I can see how this isn't quite a dupe, but I think the challenge as it stands boils down to simply "generate the largest number in 40 or so bytes". 1: Find a language with arbitrary precision integers, 2: Find a quine for this language, 3: Adapt the quine to include an incrementing number (100-byte limit does not apply to subsequent programs), 4: in the increment step, compare this number to some large number, (e.g. 3^^^3) and reset to 0 when reached. Overhead of all that will be some small number of bytes, and likely the need to repeat the large number code twice. – Dave – 2016-08-27T10:16:00.483
In fact, comparing against a large number probably isn't even needed, since no language has truly arbitrary-precision integers (most would cap out at something like 2^(2^64) or so) – Dave – 2016-08-27T10:19:09.053
1@Dave the challenge is precisely about specifying a large number in a small number of bytes, yes. That is the whole principle around which it was designed. The question is, is 3^^^3 the highest number you can specify in 100 bytes in your language, or is there a larger one? That's what this challenge is about. It's the core of it. It's what I wanted to see people do. It's super, super frustrataing to have it closed based on a superficial resemblence to a challenge that has nothing of this structure. – Nathaniel – 2016-08-27T10:19:30.190
1@Dave (second comment) but if you're clever, you need not be limited by machine precision at all. I would expect competitive answers to have a period much longer than 2^(2^64). – Nathaniel – 2016-08-27T10:20:22.560
3
So would you prefer it to be closed as a duplicate of http://codegolf.stackexchange.com/q/18028/194 ?
– Peter Taylor – 2016-08-27T10:56:14.6931@PeterTaylor that's a much closer theme, but it's still a very different challenge - printing a number is quite different from doing something a large number of times. I would of course prefer it not to be closed at all. – Nathaniel – 2016-08-27T11:45:03.187
1
@PeterTaylor a much closer duplicate would be http://codegolf.stackexchange.com/questions/44560/combinator-quines?noredirect=1#comment222555_44560. The big difference is that my question allows any language whereas that one restricts to combinator calculi only, which IMHO is a good reason not to close mine as a duplicate.
– Nathaniel – 2016-08-27T12:13:27.223Is randomness allowed? – PyRulez – 2017-06-08T17:20:32.350
1@PyRulez I'd have to say no, because that would require some tricky additional decisions to me made about how to score non-deterministic submissions. – Nathaniel – 2017-06-09T01:09:34.477