Die Aussicht auf diese Herausforderung ist:
- Wenn Ihr Programm normal ausgeführt wird, sollte der gesamte Code in den Sprachmarkierungen (
"
- doppelte Anführungszeichen) gedruckt werden. - Wenn Ihr Programm in doppelte Anführungszeichen eingeschlossen ist (die Sprachmarkierungen werden umgekehrt), sollte der Code gedruckt werden, der normalerweise nicht in Anführungszeichen steht.
Z.B:
Angenommen, Sie haben den folgenden Code:
fancyStuff("myCode"); "I like".isGreat();
Wenn ich es laufen lasse, würde ich eine Ausgabe von erwarten:
myCode
I like
Wenn ich es jedoch in Anführungszeichen setze, erhalte ich:
"fancyStuff("myCode"); "I like".isGreat();"
Wenn dieser Code ausgeführt wird, wäre die erwartete Ausgabe:
fancyStuff(
);
.isGreat();
Offensichtlich ist das obige Beispiel keine funktionale Antwort in irgendeiner Sprache. Ihre Aufgabe ist es, den Code zu schreiben, der auf diese Weise ausgeführt wird.
Regeln
- Es gelten Standardlücken.
- Die gedruckten Werte, sowohl in Anführungszeichen als auch in nicht Anführungszeichen, dürfen nicht leer sein oder nur aus Leerzeichen bestehen. Dies bedeutet auch, dass alle Programme mindestens einen Satz von Anführungszeichen enthalten müssen.
- Es ist jedoch zulässig, Leerzeichen nach- oder voranzustellen.
- Sie müssen sich nicht Ihren eigenen Code, die erforderlichen Dateinamen usw. ansehen.
- Nicht übereinstimmende Angebote sind nicht zulässig
- Wenn mehrere Zeichenfolgen vorhanden sind, können diese entweder als Zeilenumbrüche (wie im Beispiel) oder auf andere für den Menschen lesbare Weise gedruckt werden - ohne Arrays oder Objekte
- Das ist Code-Golf , also gewinnt die kürzeste Antwort in Bytes.
code-golf
restricted-source
quine
Geza Kerecsenyi
quelle
quelle
Antworten:
Python 2, 20 bytes
-7 bytes thanks to tsh
Try it online!
Old answer:
Python 2, 27 bytes
Try it online!
Train of thought behind this answer:
Begin with a simple print, because we need to print something.
We also need to print something in the inverted case, ie. have a print inside quotes.
The non-inverted case is pretty good at this point. Let's focus on the inverted case. We now start with the string
print
, which can't be followed immediately by a print statement. Let's fix this with a semicolon.Good stuff. Except, the inverted code doesn't actually print anything. We'll need to print the
print
at the start, because it ends up in quotes, but also print whatever comes after the second quote, because it ends up in quotes too. The obvious way around this is to appendprint
and multiply the last string by 2.Now the inverted code works fine, though we have to be wary of the fact that the section before the first quote and the section after the second quote need to be kept the same throughout future changes. As for the non-inverted code, it throws a syntax error - once again, we need to introduce a semicolon to separate expressions.
Python doesn't really like the look of that lone semicolon, so we must satisfy the snake's hunger with two of the same no-op expression, inserted before the first semicolon and the last semicolon. Most expressions will work fine in the first case, but in the second case it must follow
print";print 2*"
in the non-inverted code without breaking anything. We can use''
, which simply gets concatenated with the prior string.quelle
print(";print('print()');")
is also 27 bytes, and also Python 3.CSS, 66 bytes
Not so much questions may be solved by CSS...
quelle
body:after
also works on some implementations?:after
is available in most browsers for backward compatibility reasonHQ9+[see notes below], 1016 bytes
Use the implementation on https://esolangs.org/w/index.php?title=HQ9%2B&oldid=59995 and compile the interpreter with MinGW GCC 5.3.0 on Windows. I'm not sure if it works with other version of compiler, since an undefined behavior of C is required to terminate the program. The buffer is 1000 bytes long. And source code greater than 1000 bytes do the trick. I'm not sure how these happened.
quelle
05AB1E, 4 bytes
Outputs concatenated without separator.
Try it online or try it online with surrounding quotes.
Explanation:
quelle
Japt, 4 bytes
Try it unquoted or quoted
P
is the Japt variable for the empty string and thes
method slices a string - without any arguments, it does nothing.Or, ever so slightly less trivial:
Try it unquoted or quoted
The first one uppercases
+
and the second one appendsu
to an empty string.quelle
C# (Visual C# Interactive Compiler),
1131121077064 bytesSaved 5 bytes thanks to @negative seven
Unquoted and Quoted
After a while, I realized that my solution was too complicated. The newest program shown here simply hides the rest of the program in a comment to avoid errors when wrapped in quotes.
When wrapped in quotes,
Write(
is passed onto an extension method, which prints it along with);
.quelle
Split()
->Trim()
, andvar a
->_
Remove
andInsert
on it, now I can just use an extension method!Perl 6, 11 bytes
Try it online!
Prints
.say~
with a trailing newline. Seems too easy. Am I missing something?When wrapped in quotes, produces
say
with a space and trailing newline.quelle
Foo, 4 bytes
Try it online! Also works in Japt.
5 bytes (UTF-8)
Try it online! Also works in 05AB1E.
9 bytes
Try it online! Also works in Runic Enchantments.
11 bytes
Try it online! Also works in Perl 6.
20 bytes
Try it online! Also works in Python 2.
69 bytes
Try it online! Also works in CSS.
Hmm... Foo is a highly adaptable language.
quelle
"a"b
1"2"
also works in Foo. The only answer in this challenge that is not a Foo polyglot so far is in HQ9+, because the Foo interpreter also has the overflowing problem.><>,
189 bytes-9 bytes thanks to Jo King
Try it online! (quoted)
Explanation
quelle
Befunge-98 (FBBI), 12 bytes
Unquoted Quoted
Both cases print
<@,k4
. Either (or both) of the@
s can be replaced withq
instead.quelle
Runic Enchantments, 9 bytes
Try it online! and
""!""$;"$;"
From Kevin Cruijssen, who essentially fixed my first attempt utilizing what I did in my second.
Going down the "fungoids never have unmatched quotes" rule-bending "there's something about this that shouldn't be OK" route, alluded to in my own comment:
7 bytes
Try it online! and
"0".""$;"
Under normal circumstances, this program executes as
0".""$;0".""$;
pushing an integer0
, then the string.
, concatenates$;0
, NOP, concatenates an empty string, prints top-of-stack (the string.$;0
) and terminates. Wrapping it in quotes produces"0".""$;"
which pushes a string-0
, NOPs, concatenates an empty string, prints top-of-stack, and terminates (rendering the previously un-printed integer0
in string form). The last"
is left unexecuted (and not part of the original program anyway).Fungoids don't have string literals, they have a command that toggles "read own source as a string" mode and some form of "instruction pointer has reached the source boundary" rule (usually edge-wrap), so the same source-code-positional-byte acts as both "begin string" and "end string" instruction, creating a string literal of that entire row/column (excluding the
"
itself).quelle
$;
at the end in the quoted version."$;
and""$;"
(Runic wrap-around quotes pairing with themselves).!.
(which is correct), but shouldn't your program with quotes output0$;
? PS: I don't know Runic Enchantments at all, but a potential fix based on your current layout which I think is valid would be0"!""$;"$;
(which outputs!$;
as is, or outputs0$;
if surrounded with quotes). EDIT: Actually, I think you can drop the0
and output!$;
and$;
.$
is "print top of stack" and;
terminates. But you essentially got a valid answer.Haskell, 31 bytes
Try it online! Or enclosed in quotes: Try it online!
quelle
MathGolf, 4 bytes
Try it online!
The
;
andq
can be exchanged for a lot of different commands, including no-ops.quelle
Ruby, 8 bytes
Try it online!
Wraps output in quotes, which may be illegal.
Ruby, 17 bytes
Try it online!
quelle
JavaScript (SpiderMonkey), 25 bytes
Try it online!
Try it online!
Trivial but functional.
quelle
Japt, 4 bytes
Unquoted, it converts the string
P
to uppercase. Quoted, it printsu
.Try it
Japt, 4 bytes
Unquoted, it reverses the string
P
. Quoted, it printsw
.Try it
quelle
Q
instead ofP
, it's more meta! ;)R, 16 bytes
Note that the above code is not wrapped in the additional quotation marks and has both leading and trailing spaces.
Try it (non-wrapped version)
quelle
AppleScript, 9 bytes
Explained:
Quoted:
quelle