6
\$\begingroup\$

Based on a comment by Jo King on my previous question (called 'Inverse-quotes-quine'), I present this new question. The rules are similar, but just, the opposite:

  • If your program is run normally, all of the code not in the speech marks (" - double quotes) should be printed.
  • If your program is wrapped in double quotes (in turn inverting the speech marks), the code that is normally n̶o̶t̶ in quotes should be printed.

E.g:

Let's say you have the following code:

fancyStuff("myCode"); "I like".isGreat();

If I run it, I would expect an output of:

fancyStuff(
); 
.isGreat();

However, if I wrapped it in quotes, I would get:

"fancyStuff("myCode"); "I like".isGreat();"

When this code is run, the expected output would be:

myCode
I like

Obviously, the above example is not a functional response in any language. Your job is to write the code that performs in this way.

Rules

  • Standard loopholes apply.
  • The printed values, in both quoted and unquoted forms, must be non-empty, or consist solely of whitespace. This also means that all programs must include at least one set of quotes.
  • However, trailing/preceeding whitespace is allowed.
  • The quoted and unquoted strings must print different results.
  • No looking at your own code, required file names, etc.
  • Unmatched quotes are disallowed
  • If there are multiple strings, they can either be printed as newlines (as in the example), or in some other human-readable way - no arrays or objects
  • This is , so shortest answer in bytes wins.
\$\endgroup\$
  • \$\begingroup\$ So, if i understand correctly, any answers in that question which print the same string for both raw and wrapped source is also valid to this one. \$\endgroup\$ – tsh Jun 22 at 12:16
  • \$\begingroup\$ @tsh technically correct, but I should probably add a rule against that... \$\endgroup\$ – Geza Kerecsenyi Jun 22 at 12:19
3
\$\begingroup\$

Python 2, 32 bytes

''*2;print"''*2;print"''*2;print

Try it online!

Based on my initial solution for the other variant of this puzzle.

\$\endgroup\$
3
\$\begingroup\$

><>, 39 16 bytes

"l2*0.|or|["090.

Try it online! (quoted)

Explanation

        BA
"l2*0.|or|["090.
"l2*0.|or|["     Pushes the quoted characters onto the stack
            0    Pushes 0
             90. Goes to A
          [      Wipes the stack (requires the 0)
"          "090. Pushes the quoted characters onto the stack
 l2*0.           Length is 4; goes to B
      |or|       Reverses & prints the stack
A        B
""l2*0.|or|["090."
""                 No-op
  l2*0.            Length is 0; goes to A
 "l2*0.|or|["      Pushes the quoted characters onto the stack
             0     Pushes 0
              90.  Goes to B
       |or|        Reverses & prints the stack

Old answer, 39 bytes

"!~l?!<r&[orl&"0[c2*&d0.>o<~~.!?@@0+1fl

Try it online! (quoted)

Whew, this took a while. Can probably be golfed further.

             A
"!~l?!<r&[orl&"0[c2*&d0.>o<~~.!?@@0+1fl
"!~l?!<r&[orl&"                         Pushes the quoted characters onto the stack
               0[                       Wipes the stack
                 c2*&                   Puts 24 into the register (&)
                     d0.                Goes to A
"             "0[c2*&d0.>o<~~.!?@@0+1fl Pushes the quoted characters onto the stack
 !~l?!<                                 No-op (in this case)
       r                                Reverses the stack
        &[                              Wipes the stack, preserving the top &
          o                             Outputs the top character on the stack
           r                            Reverses the stack
            l&                          Puts the current length of the stack into the register
                                        Repeats until &=0, then errors
                B
""!~l?!<r&[orl&"0[c2*&d0.>o<~~.!?@@0+1fl"
""!~                                      No-op
    l?!<                                  Reverses the IP direction
""!~l?!                                 " No-op
                            ~~.!?@@0+1fl  If the length is 0, go to B
""!~l?!<r&[orl&"                        " Pushes the quoted characters onto the stack (backwards)
                            ~~.!>@@0+1fl  No-op (length != 0)
                         >o<              Outputs all the characters on the stack, then errors

(Note: when I "wipe" the stack, it really creates a new stack; the old stack is still there and accessible)

\$\endgroup\$
2
\$\begingroup\$

05AB1E (legacy), 5 bytes

·"·"·

Outputs concatenated without separator.

Try it online or try it online with surrounding quotes.

Explanation:

         # Program without surrounding quotes will output string "··"
·        # Double the top of the stack, which is empty, so an empty string is pushed
 "·"     # Push string "·" to the stack
    ·    # Double it (2*). Since the legacy version is built in Python, the string is
         # concatenated with itself: "··"
         # (output the top of the stack implicitly as result)

         # Program with surrounding quotes will output string "·"
"·"      # Push string "·" to the stack
   ·     # Double it to string "··"
    "·"  # Push string "·" to the stack
         # (output the top of the stack implicitly as result)
\$\endgroup\$
1
\$\begingroup\$

Gol><>, 9 bytes

 `H"H` "H

Try it online! Quoted version.

\$\endgroup\$
1
\$\begingroup\$

><>, 17 bytes

"af0.|o<"i!.1!0<9

Try it unquoted! Quoted!

\$\endgroup\$
1
\$\begingroup\$

Runic Enchantments, 11 bytes

!"!""!$;"$;

Try it online! and "!"!""!$;"$;"

Just a one-byte 'inversion' of the prior answer (and 1 byte for having to include the inverting-byte as part of a string literal as well).

Explanation

Note that . is a NOP command and used as a spacer where other commands are not executed or otherwise removed for explanatory purposes.

!" is effectively NOP, resulting in the execution of only ...."!$;"$; which prints the contents of the code not contained between quote-pairs (!........$;)

Wrapping everything in quotes causes the first !" to be string literal, resulting in "!".."!$;"$;. and which prints the parts of the program contained within quote-pairs ("!" and "!$;").

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.