
A Quine Puzzle - wgreenberg
http://wgreenberg.github.io/quine.zip/index.html
======
jameshart
The 'repeat' command ("repeats the last M lines of output, starting N lines
from the end") isn't very well described by the documentation, so some
experimentation is required. 'repeat M N' will produce no output at all when
the output is empty, but will always produce M lines of output, by repeatedly
looping through the last (min(N, lines of output)) lines of the output, when
the output is not. That's not very intuitive.

~~~
wgreenberg
Agreed, the descriptions could use some work. That said, I tried to strike a
balance between correctness and simplicity when describing the commands so
people could quickly get to trying stuff out.

I do show that particular edge case (along with "print 0") in the examples,
though.

------
matchu
Does there exist a solution that doesn't rely on undefined repeat behavior? I
finally gave in and looked at the answers, but it looks like they all use
`repeat M N>M`, or `repeat M N>currentOutputSize`.

I kinda assumed that the interpreter was just there for convenience, and that
its implementation of undefined behavior was irrelevant. But is the
interpreter's implementation critical to the solution?

(Then again, I'm now reading the examples and realizing that the
implementation of undefined behavior was front-and-center, so that's kinda my
bad xP)

~~~
justinpombrio
Got it!

cHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMw0KcmVwZWF0IDIgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMw0KcmVwZWF0IDIgMg0KcmVwZWF0IDMgMw0KcmVwZWF0IDIgMg==

------
daveloyall
Spoiler:

cmVwZWF0IDMgMgpwcmludCAyCnJlcGVhdCAzIDIKcHJpbnQgMgpyZXBlYXQgMyAyCg==

~~~
JoshTriplett
Variant that doesn't rely on potentially undefined behavior of asking "repeat"
to repeat before the beginning:

cHJpbnQgMApwcmludCAyCnByaW50IDAKcHJpbnQgMgpwcmludCAwCnJlcGVhdCAzIDIKcHJpbnQgMgpyZXBlYXQgMyAyCnByaW50IDIKcmVwZWF0IDMgMgo=

~~~
daveloyall
Good eye.

Also, [https://github.com/wgreenberg/quine.zip/blob/gh-
pages/test/i...](https://github.com/wgreenberg/quine.zip/blob/gh-
pages/test/interpreterSpec.js#L151)

~~~
JoshTriplett
Sure, but LZ doesn't necessarily allow that.

------
TheLoneWolfling
A related idea:

It should be possible to write a zip (rar?) file that encodes a PRNG, such
that it contains one zip: itself with the PRNG stepped forward one. (Even a
"PRNG" that just outputs 1, then 11, then 111, etc, would be sufficient in
most cases)

The hard part is making sure the checksum is consistent.

This would wreak havoc with any file checker that checks for recursive archive
files.

------
jimmaswell
empty input gets empty output, solved

~~~
daveloyall
[http://www0.us.ioccc.org/1994/smr.hint](http://www0.us.ioccc.org/1994/smr.hint)

~~~
jimmaswell
That's where I got the idea

------
personjerry
My solution, featuring only 2 distinct commands, no NOPs, and not relying on
`repeat` at the beginning:
cHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMg==

~~~
Yen
Maybe it copy-pasted wrong, but this doesn't look like a solution to me. The
output is shorter than the input, and contains commands in a different order.

~~~
personjerry
I just tried it again, and then copy pasted from the output to the input; it
still works. Did you select the full string and decode with base64?

~~~
Yen
hmm. Just tried it again, and it worked now. Nice job getting one that doesn't
start with repeat!

------
AaronFriel

        cHJpbnQgMQpwcmludCAxCnByaW50IDEKcHJpbnQgMQpwcmludCAxCnByaW50IDEKcmVwZWF0IDMg
        MgpwcmludCAyCnJlcGVhdCAzIDIKcHJpbnQgMgpyZXBlYXQgMyAyCgo=
    

Wasn't terribly difficult, though not the shortest. What's the code golf
answer?

~~~
spacehome
I wrote an program to exhaustively search (in an intelligent way so that it
terminates before the universe does). The minimal to do it without depending
on undefined repeat behavior is 10 statements (and there's only one of this
length). It's posted by JoshTriplett.

------
spacehome
I made an Objective-C command-line tool that exhaustively searches for
solutions.

[http://pastebin.com/H2nZ9Fxz](http://pastebin.com/H2nZ9Fxz)

It found JoshTriplett's 10-line solution and shows that it's minimal if you
don't allow undefined REPEAT behavior, and it found daveloyall's 5-line
solution and shows that it's minimal of you do allow undefined REPEAT
behavior.

------
krajzeg
A variant featuring only one number:
cmVwZWF0IDQgNA0KcHJpbnQgNA0KcmVwZWF0IDQgNA0KcHJpbnQgNA0KcmVwZWF0IDQgNA0KcHJpbnQgNA0KcmVwZWF0IDQgNA0KcHJpbnQgNA0K

------
thrwwy457
repeat 4 2 print 2 repeat 4 2 print 2 repeat 4 2 print 2

------
anderskaseorg
Challenge: find a solution with no undefined repeat behavior and no more than
two consecutive print statements.

------
1arity
print 2 print 2 print 2 print 2 print 2 print 2 print 2 print 2 print 2 repeat
3 2 print 2 repeat 3 2 print 2 repeat 3 2

~~~
sirtel
It seams there are more than one solutions. Can we generalize a theory of this
phenomenon?

~~~
ectoplasm
It's probably a good chunk of a PhD thesis to come up with both the theory and
an arbitrary generator for any language. However, you could probably brute
force your way to the shortest solution in this particular language fairly
easily.

------
brownbat
cmVwZWF0IDQgNA0KcHJpbnQgMg0KcmVwZWF0IDQgNA0KcHJpbnQgMg0KcmVwZWF0IDQgNA0KcHJpbnQgMg==

