Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

edited body
Source Link

GolfScript, 11 chars

{`".~"+=}.~

Without the =, this code would be a quine that generates its own source code as a string. The = makes it compare this string to its input and output 1 if they match and 0 if they don't. Note that the comparison is exact — in particular, a trailing newline at the end of the input will cause it to fail.

Explanation:

  • { } is a code block literal in GolfScript;
  • . duplicates this code block, and ~ executes the second copy (leaving the first on the stack);
  • ` stringifies the code block, and ".~"~"++ appends .~ to it;
  • finally, = compares the resulting string with the input (which is pushed on the stack as a string by the GolfScript interpreter before the program starts) and returns 1 if they match and 0 if they don't.

GolfScript, 11 chars

{`".~"+=}.~

Without the =, this code would be a quine that generates its own source code as a string. The = makes it compare this string to its input and output 1 if they match and 0 if they don't. Note that the comparison is exact — in particular, a trailing newline at the end of the input will cause it to fail.

Explanation:

  • { } is a code block literal in GolfScript;
  • . duplicates this code block, and ~ executes the second copy (leaving the first on the stack);
  • ` stringifies the code block, and ".~"+ appends .~ to it;
  • finally, = compares the resulting string with the input (which is pushed on the stack as a string by the GolfScript interpreter before the program starts) and returns 1 if they match and 0 if they don't.

GolfScript, 11 chars

{`".~"+=}.~

Without the =, this code would be a quine that generates its own source code as a string. The = makes it compare this string to its input and output 1 if they match and 0 if they don't. Note that the comparison is exact — in particular, a trailing newline at the end of the input will cause it to fail.

Explanation:

  • { } is a code block literal in GolfScript;
  • . duplicates this code block, and ~ executes the second copy (leaving the first on the stack);
  • ` stringifies the code block, and ".~"+ appends .~ to it;
  • finally, = compares the resulting string with the input (which is pushed on the stack as a string by the GolfScript interpreter before the program starts) and returns 1 if they match and 0 if they don't.
Source Link
Ilmari Karonen
  • 21k
  • 5
  • 55
  • 101

GolfScript, 11 chars

{`".~"+=}.~

Without the =, this code would be a quine that generates its own source code as a string. The = makes it compare this string to its input and output 1 if they match and 0 if they don't. Note that the comparison is exact — in particular, a trailing newline at the end of the input will cause it to fail.

Explanation:

  • { } is a code block literal in GolfScript;
  • . duplicates this code block, and ~ executes the second copy (leaving the first on the stack);
  • ` stringifies the code block, and ".~"+ appends .~ to it;
  • finally, = compares the resulting string with the input (which is pushed on the stack as a string by the GolfScript interpreter before the program starts) and returns 1 if they match and 0 if they don't.

AltStyle によって変換されたページ (->オリジナル) /