News for hackers. Stuff that matters.
Re:A Quine Puzzle by jameshart on Monday July 20, 2015 @05:02PM (#9919062)
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.
Re:A Quine Puzzle by wgreenberg on Monday July 20, 2015 @05:10PM (#9919104)
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.

Re:A Quine Puzzle by matchu on Monday July 20, 2015 @11:52PM (#9920485)
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)

Re:A Quine Puzzle by justinpombrio on Tuesday July 21, 2015 @02:31AM (#9920810)
Got it!

cHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMw0KcmVwZWF0IDIgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMw0KcmVwZWF0IDIgMg0KcmVwZWF0IDMgMw0KcmVwZWF0IDIgMg==

Re:A Quine Puzzle by wgreenberg on Tuesday July 21, 2015 @04:22PM (#9925492)
Although I may be mistaken, LZ77 defines the repeat behavior to do exactly that: https://en.wikipedia.org/wiki/LZ77_and_LZ78#Example
Re:A Quine Puzzle by daveloyall on Monday July 20, 2015 @04:12PM (#9918696)
Spoiler:

cmVwZWF0IDMgMgpwcmludCAyCnJlcGVhdCAzIDIKcHJpbnQgMgpyZXBlYXQgMyAyCg==

Re:A Quine Puzzle by JoshTriplett on Monday July 20, 2015 @04:48PM (#9918961)
Variant that doesn't rely on potentially undefined behavior of asking "repeat" to repeat before the beginning:

cHJpbnQgMApwcmludCAyCnByaW50IDAKcHJpbnQgMgpwcmludCAwCnJlcGVhdCAzIDIKcHJpbnQgMgpyZXBlYXQgMyAyCnByaW50IDIKcmVwZWF0IDMgMgo=

Re:A Quine Puzzle by daveloyall on Monday July 20, 2015 @06:16PM (#9919478)
Re:A Quine Puzzle by JoshTriplett on Monday July 20, 2015 @11:10PM (#9920374)
Sure, but LZ doesn't necessarily allow that.
Re:A Quine Puzzle by sevenfive on Tuesday July 21, 2015 @01:53AM (#9920733)
How do you use these strings?
Re:A Quine Puzzle by JoshTriplett on Tuesday July 21, 2015 @02:02AM (#9920753)
They're base64. Feed them to "base64 -d" on Linux, or one of the many base64 decoders on the web. See https://en.wikipedia.org/wiki/Base64
Re:A Quine Puzzle by mattdodge on Monday July 20, 2015 @07:18PM (#9919723)
This is the shortest one of the solutions so far. Wonder if it's the shortest possible? (Other than empty = empty)
Re:A Quine Puzzle by spacehome on Tuesday July 21, 2015 @06:13PM (#9926244)
Yes. It is the unique shortest possible solution if you allow for a repeat at the beginning. OTOH if you disallow starting with a REPEAT, the shortest is length 10.
Re:A Quine Puzzle by daveloyall on Tuesday July 21, 2015 @10:35AM (#9922519)
Hm. Well, it was the first quine I arrived at. No special effort was made to make it short.
Re:A Quine Puzzle by superobserver on Monday July 20, 2015 @04:31PM (#9918846)
Another similar to your idea: cmVwZWF0IDQgMw0KcHJpbnQgMg0KcmVwZWF0IDQgMw0KcHJpbnQgMg0KcmVwZWF0IDQgMw0KcHJpbnQgMg==
Re:A Quine Puzzle by TheLoneWolfling on Monday July 20, 2015 @10:47PM (#9920317)
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.

Re:A Quine Puzzle by jimmaswell on Monday July 20, 2015 @05:27PM (#9919220)
empty input gets empty output, solved
Re:A Quine Puzzle by daveloyall on Monday July 20, 2015 @06:11PM (#9919455)
Re:A Quine Puzzle by jimmaswell on Monday July 20, 2015 @08:27PM (#9919977)
That's where I got the idea
Re:A Quine Puzzle by personjerry on Monday July 20, 2015 @04:52PM (#9918982)
My solution, featuring only 2 distinct commands, no NOPs, and not relying on `repeat` at the beginning: cHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMg0KcHJpbnQgMg0KcmVwZWF0IDMgMg==
Re:A Quine Puzzle by Yen on Monday July 20, 2015 @07:52PM (#9919854)
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.
Re:A Quine Puzzle by personjerry on Monday July 20, 2015 @08:08PM (#9919916)
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?
Re:A Quine Puzzle by Yen on Tuesday July 21, 2015 @05:18PM (#9925890)
hmm. Just tried it again, and it worked now. Nice job getting one that doesn't start with repeat!
Re:A Quine Puzzle by AaronFriel on Monday July 20, 2015 @10:33PM (#9920276)

    cHJpbnQgMQpwcmludCAxCnByaW50IDEKcHJpbnQgMQpwcmludCAxCnByaW50IDEKcmVwZWF0IDMg
    MgpwcmludCAyCnJlcGVhdCAzIDIKcHJpbnQgMgpyZXBlYXQgMyAyCgo=
Wasn't terribly difficult, though not the shortest. What's the code golf answer?
Re:A Quine Puzzle by spacehome on Tuesday July 21, 2015 @05:20PM (#9925897)
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.
Re:A Quine Puzzle by spacehome on Tuesday July 21, 2015 @06:33PM (#9926349)
I made an Objective-C command-line tool that exhaustively searches for solutions.

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.

Re:A Quine Puzzle by krajzeg on Monday July 20, 2015 @04:56PM (#9919019)
A variant featuring only one number: cmVwZWF0IDQgNA0KcHJpbnQgNA0KcmVwZWF0IDQgNA0KcHJpbnQgNA0KcmVwZWF0IDQgNA0KcHJpbnQgNA0KcmVwZWF0IDQgNA0KcHJpbnQgNA0K
Re:A Quine Puzzle by thrwwy457 on Monday July 20, 2015 @04:55PM (#9919011)
repeat 4 2 print 2 repeat 4 2 print 2 repeat 4 2 print 2
Re:A Quine Puzzle by anderskaseorg on Tuesday July 21, 2015 @04:05AM (#9920995)
Challenge: find a solution with no undefined repeat behavior and no more than two consecutive print statements.
Re:A Quine Puzzle by 1arity on Tuesday July 21, 2015 @05:18AM (#9921151)
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
Re:A Quine Puzzle by sirtel on Tuesday July 21, 2015 @05:34AM (#9921178)
It seams there are more than one solutions. Can we generalize a theory of this phenomenon?
Re:A Quine Puzzle by ectoplasm on Tuesday July 21, 2015 @05:48AM (#9921209)
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.
Re:A Quine Puzzle by 1arity on Tuesday July 21, 2015 @05:56AM (#9921226)
If you sum up the M for the active lines in a solution they equal the total number of lines. So in this one, 2 + 2 + 2 + 3 + 2 + 3 = 14.

Take 1 active line and 1 inactive line as some minimum, this contradicts, because this can only produce 1 line. 1 active line and two inactive lines, contradicts, because it can either produce 2 lines ( and it took 3 ) or it can produce m lines if the final line is a repeat, and yet this repeat is not printed.

The function of PRINT X thus becomes like a variable definition. Something needs to be "PRINTED" in order to be available for a back reference. So everything in the quine needs to itself be printed, so that it can be "printed in the quine" by back reference. This suggests that the set of different statements, being, different values of (M) and (M,N) will be conserved.

So let's assume ( and we have evidence of this ) the minimum size of statement set for a solution is 2.

What two statements can produce solutions ?

At this point, considering the above observations, one can enter the area of solving constraints on the numbers M and N through logic.

The weird thing is I wonder how you classify these languages ( of these statements such as the one given, being, a PRINT statement and a repeat statement ). It's not Turing complete. It's not a state machine. It's not a production grammar. It's not a read and say sequence. Interesting to consider what it is and what other types there are.

It also seems like there are more solutions of the same pattern.

Such as

print 2 print 2 print 2 print 2 print 2 print 2 print 2 print 2 print 2 print 2 print 2 print 2 repeat 4 2 print 2 repeat 4 2 print 2 repeat 4 2 print 2 repeat 4 2

And

One with 15 print 2 statements followed by 5 "repeat 5 2" statements delimited by "print 2" statements.

And so on. The pattern is (3 * x) * "PRINT 2" + (x - 1) * "REPEAT X 2\nPRINT 2" + "REPEAT X 2"

For the other type "repeat 3 2 print 2 repeat 3 2 print 2 repeat 3 2" ( of which the version with m = 4 contains a terminating "print 2", and m = 5 doesn't work since in that case the M's sum to 2 + 2 + 5 = 9 lines of output, and there are only 8 statements in the source. Changing the active repeat statement from "repeat 5 2" to "repeat 4 2" with 2 + 2 + 4 gives 8 statements in the output and the source, and we can then do this:

repeat 4 2

print 2

repeat 4 2

print 2

repeat 4 2

print 2

print 123123123211231

repeat 12312312 123123123

And it always works to echo whatever the last two lines are, so in that sense, the above "code" is like a "PRINT" function.

A "concat" function can be obtained like so :

repeat 5 2

print 2

repeat 5 2

print 2

repeat 5 2

print 2

repeat XXX YYY

==> and the output is the source + "repeat 5 2" + "repeat XXX YYY"

So this function concatenates "repeat 5 2" and "repeat XXX"

Likely other "primitives" can be constructed. It's interesting to consider what the "product space" of these would be. What functionality could be derived from this simple language ?

Re:A Quine Puzzle by brownbat on Tuesday July 21, 2015 @01:52AM (#9920732)
cmVwZWF0IDQgNA0KcHJpbnQgMg0KcmVwZWF0IDQgNA0KcHJpbnQgMg0KcmVwZWF0IDQgNA0KcHJpbnQgMg==