Double-slit Quine

11

1

Objective:

Code two programs where each of the programs outputs both source codes interlaced per character like a zipper, a Double-slit Quine. The output from a Double-slit Quine is starting with the first character from the source code of the first program. If the source code of one of the programs is shorter in length than the other, then the rest of the output must be filled with the rest of the longer source code.

Rules:

  1. You can use any programming language for both programs, not necessary the same programming language for both.
  2. Your programs should not take any input from a file, file name, network, the other program or anything else.

Mandatory criteria:

  • There is a catch, somewhere in the output the word QUINE in capital letters must exist, uninterrupted.
  • You need to state what two programming languages you are using. If you are using the same programming language for both, then you only need to state one programming language.
  • Both programs should be able to execute, or be interpreted, respectively independent of the other program.

Example:

Having this example source code of program one:

"QIE"

Having this example source code of program two:

"UN"

Then the valid Double-slit Quine output from both programs must be:

""QUINE""

This is code-golf, the least bytes when summing the length of both source codes, and obviously also the length of each programs output, wins!

Plarsen

Posted 2015-05-29T19:42:56.333

Reputation: 1 740

Each individual program doesn't have to be a quine also, correct? And must each program contain at least one character? – mbomb007 – 2015-05-29T20:25:50.230

@mbomb007 That is correct. Each individual program should output both source code characters like a zipper from start to end. Well, I guess you'll need at least 1 byte in a programing language to output QUINE? The output from both programs must be identical. – Plarsen – 2015-05-29T20:28:18.233

I'm not sure I understand the rest of the output must be filled with the rest of the longer source code correctly. How would A and XYZ be interleaved? AXYZ? – Dennis – 2015-05-29T20:29:54.037

@Dennis Just like .+ or z works – Optimizer – 2015-05-29T20:30:56.483

@Dennis Correct. What is left from the longer source code when the shorter runs out of bytes must be appended to the output from both programs. – Plarsen – 2015-05-29T20:31:15.700

Must the two programs have a Levenshtein distance of at least 1? – quintopia – 2015-12-25T02:29:36.497

@quintopia I don't think this task is possible with two identical programs, since the output must contain the word QUINE. – Dennis – 2015-12-25T03:17:02.047

@Dennis I'm thinking you are right. – quintopia – 2015-12-25T03:21:38.887

Answers

9

CJam, 49 47 bytes

{`:_"__~~e#QUINE"}_~

and

{`:_"__~~e#QUINE"}_~e#QUINE

both print

{{``""__~~""++::__""ee##QQUUIINNEE""}}__~~e#QUINE

Try it online: program 1, program 2, proof of validity

How they work

{                }   e# Push a code block.
                  _~ e# Execute a copy.
 `                   e# Convert the code block into a string.
  :_                 e# Duplicate each character of the resulting string.
    "__~~e#QUINE"    e# Push this string.

Program 1 finishes here and has a string representation of its entire source code (which each character repeated twice) as well as the string e#QUINE on the stack.

Program 2 additionally parses e#QUINE, which is a comment.

In both cases, CJam prints the two strings automatically, resulting in the aforementioned output.

Dennis

Posted 2015-05-29T19:42:56.333

Reputation: 196 637

4

Seriously, 46 56 42 bytes

QUNX;RZtdXεj.ƒ£REIQ

Hex Dump:

51554e583b525a746458ee6a2e7f9f9c524549510a

The second program is this exact program reversed. It does contain an invisible character, but the byte count is correct. Both programs output this palindromic string:


QQUINEXR;£RƒZ⌂t.djXεεXjd.t⌂ZƒR£;RXENIUQQ

(For some reason it displays the invisible character when it outputs it in my terminal. I don't really understand that 7F byte.)

How it works:

Q                     Push the source to the stack
 U                    Nop
  NX                  Push and pop lyrics to 99 bottles of beer
    ;R                Make a copy of the source reversed.
      Z               Zip them together.
       t              Completely flatten the list.
        dX            Delete the trailing newline
          εj          Join it into a string.
            .         Print it with a trailing newline.
             ⌂        (This is that 7F byte that won't show up. It halts.)

The rest of the program is not executed.

Then the other direction:

\n                   Nop
  Q                  Push the source code.
   IE                Nops
     R               Reverse source code to get source of first program
      £              Eval it into a function
       ƒ             Call it.

At this point, we are now running the first program above, so execution continues as described there.

I am heavily exploiting the fact that several commands do nothing to strings or empty stacks here. I'm also exploiting the unexpected behavior of t when there is only one item on the stack. Do not expect this program to work in future versions of Seriously.

As the online version of the Seriously interpreter continues to be broken, you'll have to download the interpreter and run it on your own machine to test it.

quintopia

Posted 2015-05-29T19:42:56.333

Reputation: 3 899

@Dennis did you test it on your computer? That may be an artifact of my own build environment. – quintopia – 2015-12-25T23:57:24.633

@Dennis nvm you're right. All of Seriously's output methods add a linefeed. I can fix it at the cost of 8 bytes. Looks like your method will be shorter (which is sad because this method is cooler IMO). – quintopia – 2015-12-26T02:13:01.817

1

Perl, 61+60=121 bytes

Program 1:

$x=q<print"\$x=q<$x>;eval\$x#"=~s/./$&$&/gr,QUINE>;eval$x#QIE

Program 2:

$x=q<print"\$x=q<$x>;eval\$x#"=~s/./$&$&/gr,QUINE>;eval$x#UN

I thought I'd give this a go in a non-golfing language. This is basically just a universal quine constructor in Perl modified to double every character before printing it, and append QUINE to the end. Then we just have to stick a comment at the end of the code to compensate for the added text.

(I wrote this without really looking at the other answers. Turns out it'd be possible to save a byte by putting the entire comment in one program, but I'm not sure if I should just be blatantly copying algorithms like that.)

user62131

Posted 2015-05-29T19:42:56.333

Reputation:

1

GolfScript, 46 bytes

{`{.}%"..~~QUINE"}.~

and

{`{.}%"..~~QUINE"}.~QUINE

both print

{{``{{..}}%%""....~~~~QQUUIINNEE""}}..~~QUINE

Try it online: program 1, program 2, proof of validity

How it works

{`{.}%"..~~QUINE"}.~

{                }    # Push a code block.
                  .~  # Execute a copy.
 `                    # Convert the code block into a string.
  {.}%                # Duplicate each character of the resulting string.
      "..~~QUINE"     # Push that string.

The source code of program 2 additionally parses QUINE\n, which are two undefined tokens.

Dennis

Posted 2015-05-29T19:42:56.333

Reputation: 196 637