I reverse the source code, you negate the output!I reverse the source code, you negate the input!Meta Length LogarithmsZeroes in intervalI double the source, you double the output!Double-time is not double timeThird time the charmQuine outputs itself in binaryI multiply the source, you (probably) multiply the output!I reverse the source code, you negate the input!
Dear Fellow PSE Users,
Incorrect syntax near '+' in stored procedure sql server
Is it safe to put a microwave in a walk-in closet?
Why is it called a Blood Knot?
Regular Expressions with `<` and `?` strange matches
What are sources for Magic Items that are not adventure-specific?
Weapon class firing logic in JavaScript
Lead Amalgam as a Material for a Sword
Is the name of an interval between two notes unique and absolute?
Simulate a 1D Game-of-Life-ish Model
Algorithm for competing cells of 0s and 1s
Is Zack Morris's 'time stop' ability in "Saved By the Bell" a supernatural ability?
What to do as a player when ranger animal companion dies
Convert dictionaries with list of values into a dataframe
What is the origin of the "being immortal sucks" trope?
What was the deeper meaning of Hermione wanting the cloak?
I feel like most of my characters are the same, what can I do?
Why is the stock market so unpredictable?
Why does Canada require a minimum rate of climb for ultralights of 300 ft/min?
What is the maximum viable speed for a projectile within earth's atmosphere?
Integrability of log of distance function
Is there any reason nowadays to use a neon indicator lamp instead of a LED?
Unable to see packet drops on tunnels
Who are the people reviewing far more papers than they're submitting for review?
I reverse the source code, you negate the output!
I reverse the source code, you negate the input!Meta Length LogarithmsZeroes in intervalI double the source, you double the output!Double-time is not double timeThird time the charmQuine outputs itself in binaryI multiply the source, you (probably) multiply the output!I reverse the source code, you negate the input!
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Your task, if you wish to accept it, is to write a program that outputs a non-zero number(can be integer or float). The tricky part is that if I reverse your source code, the output must be the original integer negated.
Rules
You must build a full program. That is, your output has to be printed to STDOUT.
Both the numbers must be in base 10 (outputting them in any other base or with scientific notation is forbidden).
Your program must not take input (or have an unused, empty input).
Outputting the numbers with trailing / leading spaces is allowed.
This is code-golf, so the shortest (original) code in each language wins!
Default Loopholes apply.
Example
Let's say your source code is ABC and its corresponding output is 4. If I write CBA instead and run it, the output must be -4.
code-golf source-layout
$endgroup$
add a comment
|
$begingroup$
Your task, if you wish to accept it, is to write a program that outputs a non-zero number(can be integer or float). The tricky part is that if I reverse your source code, the output must be the original integer negated.
Rules
You must build a full program. That is, your output has to be printed to STDOUT.
Both the numbers must be in base 10 (outputting them in any other base or with scientific notation is forbidden).
Your program must not take input (or have an unused, empty input).
Outputting the numbers with trailing / leading spaces is allowed.
This is code-golf, so the shortest (original) code in each language wins!
Default Loopholes apply.
Example
Let's say your source code is ABC and its corresponding output is 4. If I write CBA instead and run it, the output must be -4.
code-golf source-layout
$endgroup$
$begingroup$
@Grimy Oh yeah.
$endgroup$
– TwilightSparkle
8 hours ago
4
$begingroup$
I don't think thekolmogorov-complexitytag is appropriate, here.
$endgroup$
– Grimy
8 hours ago
$begingroup$
@Grimy I simply compied the "I double the source code, you double the output" question, with some minor modification. If it is not appropriate here, I will remove it.
$endgroup$
– TwilightSparkle
8 hours ago
$begingroup$
If we could reverse at the bit level rather than the byte level the one byte-(0x45 = 0b00101101) works in Jelly --yields -1 since it defines the literal -1, whileṆ(0xB4 = 0b10110100) yields 1 since it performs a logical not of the implicit input of zero. (Of courseṆworks just as well :p)
$endgroup$
– Jonathan Allan
49 mins ago
add a comment
|
$begingroup$
Your task, if you wish to accept it, is to write a program that outputs a non-zero number(can be integer or float). The tricky part is that if I reverse your source code, the output must be the original integer negated.
Rules
You must build a full program. That is, your output has to be printed to STDOUT.
Both the numbers must be in base 10 (outputting them in any other base or with scientific notation is forbidden).
Your program must not take input (or have an unused, empty input).
Outputting the numbers with trailing / leading spaces is allowed.
This is code-golf, so the shortest (original) code in each language wins!
Default Loopholes apply.
Example
Let's say your source code is ABC and its corresponding output is 4. If I write CBA instead and run it, the output must be -4.
code-golf source-layout
$endgroup$
Your task, if you wish to accept it, is to write a program that outputs a non-zero number(can be integer or float). The tricky part is that if I reverse your source code, the output must be the original integer negated.
Rules
You must build a full program. That is, your output has to be printed to STDOUT.
Both the numbers must be in base 10 (outputting them in any other base or with scientific notation is forbidden).
Your program must not take input (or have an unused, empty input).
Outputting the numbers with trailing / leading spaces is allowed.
This is code-golf, so the shortest (original) code in each language wins!
Default Loopholes apply.
Example
Let's say your source code is ABC and its corresponding output is 4. If I write CBA instead and run it, the output must be -4.
code-golf source-layout
code-golf source-layout
edited 1 hour ago
AdmBorkBork
28.9k4 gold badges72 silver badges251 bronze badges
28.9k4 gold badges72 silver badges251 bronze badges
asked 8 hours ago
TwilightSparkleTwilightSparkle
4272 silver badges11 bronze badges
4272 silver badges11 bronze badges
$begingroup$
@Grimy Oh yeah.
$endgroup$
– TwilightSparkle
8 hours ago
4
$begingroup$
I don't think thekolmogorov-complexitytag is appropriate, here.
$endgroup$
– Grimy
8 hours ago
$begingroup$
@Grimy I simply compied the "I double the source code, you double the output" question, with some minor modification. If it is not appropriate here, I will remove it.
$endgroup$
– TwilightSparkle
8 hours ago
$begingroup$
If we could reverse at the bit level rather than the byte level the one byte-(0x45 = 0b00101101) works in Jelly --yields -1 since it defines the literal -1, whileṆ(0xB4 = 0b10110100) yields 1 since it performs a logical not of the implicit input of zero. (Of courseṆworks just as well :p)
$endgroup$
– Jonathan Allan
49 mins ago
add a comment
|
$begingroup$
@Grimy Oh yeah.
$endgroup$
– TwilightSparkle
8 hours ago
4
$begingroup$
I don't think thekolmogorov-complexitytag is appropriate, here.
$endgroup$
– Grimy
8 hours ago
$begingroup$
@Grimy I simply compied the "I double the source code, you double the output" question, with some minor modification. If it is not appropriate here, I will remove it.
$endgroup$
– TwilightSparkle
8 hours ago
$begingroup$
If we could reverse at the bit level rather than the byte level the one byte-(0x45 = 0b00101101) works in Jelly --yields -1 since it defines the literal -1, whileṆ(0xB4 = 0b10110100) yields 1 since it performs a logical not of the implicit input of zero. (Of courseṆworks just as well :p)
$endgroup$
– Jonathan Allan
49 mins ago
$begingroup$
@Grimy Oh yeah.
$endgroup$
– TwilightSparkle
8 hours ago
$begingroup$
@Grimy Oh yeah.
$endgroup$
– TwilightSparkle
8 hours ago
4
4
$begingroup$
I don't think the
kolmogorov-complexity tag is appropriate, here.$endgroup$
– Grimy
8 hours ago
$begingroup$
I don't think the
kolmogorov-complexity tag is appropriate, here.$endgroup$
– Grimy
8 hours ago
$begingroup$
@Grimy I simply compied the "I double the source code, you double the output" question, with some minor modification. If it is not appropriate here, I will remove it.
$endgroup$
– TwilightSparkle
8 hours ago
$begingroup$
@Grimy I simply compied the "I double the source code, you double the output" question, with some minor modification. If it is not appropriate here, I will remove it.
$endgroup$
– TwilightSparkle
8 hours ago
$begingroup$
If we could reverse at the bit level rather than the byte level the one byte
- (0x45 = 0b00101101) works in Jelly - - yields -1 since it defines the literal -1, while Ṇ (0xB4 = 0b10110100) yields 1 since it performs a logical not of the implicit input of zero. (Of course Ṇ works just as well :p)$endgroup$
– Jonathan Allan
49 mins ago
$begingroup$
If we could reverse at the bit level rather than the byte level the one byte
- (0x45 = 0b00101101) works in Jelly - - yields -1 since it defines the literal -1, while Ṇ (0xB4 = 0b10110100) yields 1 since it performs a logical not of the implicit input of zero. (Of course Ṇ works just as well :p)$endgroup$
– Jonathan Allan
49 mins ago
add a comment
|
31 Answers
31
active
oldest
votes
1 2
next
$begingroup$
05AB1E, 2 bytes
(1
Try it online!
!enilno ti yrT
( # negate nothing
1 # push 1 (and implictly output it)
1 # push 1
( # negate it (and implictly output it)
$endgroup$
1
$begingroup$
That was fast. And impressive!
$endgroup$
– TwilightSparkle
8 hours ago
add a comment
|
$begingroup$
Whitespace, 21 bytes
S S S T N
T N
S T N
N
N
T S N
T N
T T S S
Letters S (space), T (tab), and N (new-line) added as highlighting only.
Outputs 1/-1.
Try it online or try it online reversed (with raw spaces, tabs and new-lines only).
Explanation:
Utilizing the Exit Program builtin being a short palindrome NNN.
The regular program will:
SSSTN # Push 1 to the stack
TNST # Pop and print the top of the stack as number
NNN # Exit the program, making everything after it no-ops
The reverse program will:
SSTTN # Push -1 to the stack
TNST # Pop and print the top of the stack as number
NNN # Exit the program, making everything after it no-ops
Small additional explanation of pushing a number:
- First
S: Enable Stack Manipulation - Second
S: Push a number to the stack SorT: Positive/negative respectively- Some
S/Tfollowed by a trailingN: number in binary, whereS=0andT=1
I.e. SSTTSTSN pushes -10.
$endgroup$
add a comment
|
$begingroup$
JavaScript (V8), 19 bytes
print(1)//)1-(tnirp
Try it online!
almost identical to...
C# (Visual C# Interactive Compiler), 19 bytes
Print(1)//)1-(tnirP
Try it online!
(thanks to @someone for pointing it out)
but shorter in...
Python 2, 15 bytes
print 1#1-tnirp
Try it online!
Even shorter in PHP, because it has this magic printing tool: <?= ...
PHP, 12 bytes
<?=1;#;1-=?<
Try it online!
$endgroup$
$begingroup$
Also C# Interactive,Print(1)//)-1(tnirP. (Try it online!)
$endgroup$
– someone
8 hours ago
add a comment
|
$begingroup$
Runic Enchantments, 4 bytes
1@Z1
Try it online! Try it Reversed!
I couldn't find a way to re-use the 1 command, even at the expense of a byte or two.
1@ɩ also works, but is the same number of bytes.
$endgroup$
$begingroup$
Why the input? The question said your program must take no input.
$endgroup$
– TwilightSparkle
8 hours ago
$begingroup$
@TwilightSparkle I misread and already fixed it
$endgroup$
– Draco18s
8 hours ago
$begingroup$
Yeah, I see. Clever.
$endgroup$
– TwilightSparkle
8 hours ago
add a comment
|
$begingroup$
Klein 011, 5 bytes
1-
@/
Try it online!
Reversed
/@
-1
Try it online!
These take advantage of Klein's unique topology, specifically the real projective plane. (Although individually each answer only needs a Klein bottle).
$endgroup$
add a comment
|
$begingroup$
///, 4 bytes
9/9-
Outputs 9.
Try it online!
Reversed:
-9/9
Outputs -9.
Try it online!
Everything before the / is printed, while the rest is ignored (not really used slashes much so I don't know exactly what happens, but it doesn't output anything).
$endgroup$
$begingroup$
+1 for using Slashes. The/begins the pattern-reading process, and thus, the characters after it is readed into the pattern, not outputted.
$endgroup$
– TwilightSparkle
8 hours ago
add a comment
|
$begingroup$
Japt, 2 bytes
Any single digit integer >0 can be used in place of the 2 as can A-G, H, I, J or L (10-16, 32, 64, -1 & 100, respectively).
n2
Test it | Reversed
The n method when applied to an integer, subtracts that integer from the argument passed to it, which defaults to 0. When run forwards, the n method is being run on the implicit first input, which also defaults to 0.
Alternatively, the g method could be used instead of n, which gives the sign of the result of subtracting its argument from the integer it's applied to.
$endgroup$
add a comment
|
$begingroup$
PowerShell, 4 3 bytes
1-0
Try it online! or !enilno ti yrT
Golfed a byte by using arithmetic instead of the number-comment-number format.
$endgroup$
add a comment
|
$begingroup$
Cubix, 7 6 bytes
@)RO(O
Try it here
Reversed
Explanation
Cubified:
@
) R O (
O
Unrolling the control flow, we execute )O(@, which increments, outputs, decrements, and exits.
Reversed and cubified:
O
( O R )
@
Unrolling the control flow, we execute (O@, which decrements, outputs, and exits.
Previous version
@O(.)O@
Try it here
Reversed
Not as short, but much more aesthetically pleasing.
$endgroup$
$begingroup$
nice, way to put it on a size 1 cube!
$endgroup$
– Giuseppe
2 hours ago
$begingroup$
@)O(@for 5 bytes and restoration of symmetry :)
$endgroup$
– MickyT
10 mins ago
add a comment
|
$begingroup$
Jelly, 2 bytes
NC
Try it online!
Negative, results in 0, then Complement, results in 1-0 = 1.
CN
Try it online!Complement, results in 1-0 = 1. Negative, results in -1.
$endgroup$
add a comment
|
$begingroup$
APL (Dyalog Unicode), 4 3 bytes
1-0
Try it online!
Trivial answer. Prints 1 when run and ¯1 when run reversed.
$endgroup$
add a comment
|
$begingroup$
Haskell, 28 bytes
main=print 1--)1-(tnirp=niam
Try it online!
Try it enilno!
$endgroup$
add a comment
|
$begingroup$
T-SQL, 16 bytes
--Forwards:
PRINT 4--4-TNIRP
--Backwards:
PRINT-4--4 TNIRP
Picked 4 because 1 is overused :)
$endgroup$
add a comment
|
$begingroup$
Triangular, 4 bytes
i%%d
Try it online!
Outputs 1.
Ungolfed:
i
% %
d
Reversed:
d%%i
Try it online!
Outputs -1.
$endgroup$
add a comment
|
$begingroup$
MATL, 3 bytes
Nqv
Try it online!
- Normal
- Reversed
How they work
Normal:
N % Push number of elements in the stack: 0
q % Subtract 1: gives -1
v % Concatenate stack contents vertically: leaves -1 as is
% Implicit display stack contents
Reversed:
v % Concatenate stack contents vertically: gives the empty array, []
q % Subtract 1: leaves [] as is
N % Push number of elements in the stack: 1
% Implicit display. [] is not displayed
$endgroup$
add a comment
|
$begingroup$
MarioLANG, 5 bytes
+
:
-
Try it online!
Reversed:
-
:
+
Try it online!
$endgroup$
add a comment
|
$begingroup$
Ruby, 8 7 bytes
p 1#0~p
Try it online!
Thanks Arnauld for chipping off 1 byte and making it less dull.
$endgroup$
add a comment
|
$begingroup$
Java 5 or 6, 127 67 bytes
enum AA;System.out.print(9);//}};)9-(tnirp.tuo.metsyS;AA mune
Outputs 9/-9.
No online compiler, because Java 5 or 6 isn't available anywhere.
You can however try this 127 bytes Java 8 equivalent:
Try it online or try it online reversed.
Explanation:
enum A // Create an enum
A; // With a mandatory value
// And in a separate instance code-block:
System.out.print(9); // Print 9 to STDOUT
//;)9-(tnirp.tuo.metsyS;AA mune // Comment and thus a no-op
Java 5 and 6 had a bug allowing you to create a code block inside an enum to do something, despite missing a program's mandatory main-method. This will result in an error:
java.lang.NoSuchMethodError: main
Exception in thread "main"
But will still output what we'd want to STDOUT first, so we can ignore that.
$begingroup$
Charcoal, 5 bytes
ωP¹1←
Try it online! Outputs 1. Explanation:
ω Print the empty string (does nothing)
P¹ Print a `-` without moving the cursor
1 Print a `1`
← Move the cursor left (no effect on output)
Reversed:
←1¹Pω
Try it online! Outputs -1. Explanation:
←1 Print a `1` and move the cursor left
¹ Print a `-`
Pω Print the empty string (does nothing)
$begingroup$
Cubix, 7 6 bytes
@)RO(O
Try it here
Reversed
Explanation
Cubified:
@
) R O (
O
Unrolling the control flow, we execute )O(@, which increments, outputs, decrements, and exits.
Reversed and cubified:
O
( O R )
@
Unrolling the control flow, we execute (O@, which decrements, outputs, and exits.
Previous version
@O(.)O@
Try it here
Reversed
Not as short, but much more aesthetically pleasing.
$endgroup$
add a comment
;)9-(tnirp.tuo.metsyS;AA mune
Outputs 9/-9.
No online compiler, because Java 5 or 6 isn't available anywhere.
You can however try this 127 bytes Java 8 equivalent:
Try it online or try it online reversed.
Explanation:
enum A // Create an enum
A; // With a mandatory value
// And in a separate instance code-block:
System.out.print(9); // Print 9 to STDOUT
//;)9-(tnirp.tuo.metsyS;Aimprove this answer$endgroup$
add a comment
;)9-(tnirp.tuo.metsyS;AA mune
Outputs 9/-9.
No online compiler, because Java 5 or 6 isn't available anywhere.
You can however try this 127 bytes Java 8 equivalent:
Try it online or try it online reversed.
Explanation:
enum A // Create an enum
A; // With a mandatory value
// And in a separate instance code-block:
System.out.print(9); // Print 9 to STDOUT
//;)9-(tnirp.tuo.metsyS;AA mune // Comment and thus a no-op
Java 5 and 6 had a bug allowing you to create a code block inside an enum to do something, despite missing a program's mandatory main-method. This will result in an error:
java.lang.NoSuchMethodError: main
Exception in thread "main"
But will still output what we'd want to STDOUT first, so we can ignore that.
edited 7 hours ago
answered 7 hours ago
Kevin CruijssenKevin Cruijssen
51.1k7 gold badges85 silver badges247 bronze badges
51.1k7 gold badges85 silver badges247 bronze badges
add a comment
++$
Try it online!
!enilno ti yrT
The
$begingroup$
Perl 5 (-p), 12 bytes
$--++$
Try it online!
!enilno ti yrT
The pseudo-operator really comes in handy.
Perl 5 (-M5.010), 11 bytes
say 1#1-yas
Try it online!
This one is super boring, just using a comment like all the other non-golfing-language answers.
$endgroup$
Perl 5 (-p), 12 bytes
$--++$
Try it online!
!enilno ti yrT
The improve this answer
$endgroup$
add a comment
;)"1-"(stup
$begingroup$
C (clang), 39 bytes
main()puts("1");//;)"1-"(stup)(niam
Try it online!
Corrected as @AdamBorkBork error spotting.
$endgroup$
C (clang), 39 bytes
main()puts("1");//;)"1-"(stup{)(niam
Try it online!
Corrected as @AdamBorkBork error spotting.
edited 6 hours ago
answered 7 hours ago
AZTECCOAZTECCO
1831 silver badge6 bronze badges
1831 silver badge6 bronze badges
1
$begingroup$
Darn! You beat me by... 4 hours.
$endgroup$
– JL2210
3 hours ago
add a comment
|
1
$begingroup$
Darn! You beat me by... 4 hours.
$endgroup$
– JL2210
3 hours ago
1
1
$begingroup$
Darn! You beat me by... 4 hours.
$endgroup$
– JL2210
3 hours ago
$begingroup$
Darn! You beat me by... 4 hours.
$endgroup$
– JL2210
3 hours ago
add a comment
|
$begingroup$
Gaia, 4 bytes
2-”2
Try it online!
2-” | push the string "2-"
2 | push 2
| implicit print TOS
2” | push the string "2"
-2 | push -2
| implicit print TOS
$endgroup$
add a comment
|
$begingroup$
Gaia, 4 bytes
2-”2
Try it online!
2-” | push the string "2-"
2 | push 2
| implicit print TOS
2” | push the string "2"
-2 | push -2
| implicit print TOS
$endgroup$
add a comment
|
$begingroup$
Gaia, 4 bytes
2-”2
Try it online!
2-” | push the string "2-"
2 | push 2
| implicit print TOS
2” | push the string "2"
-2 | push -2
| implicit print TOS
$endgroup$
Gaia, 4 bytes
2-”2
Try it online!
2-” | push the string "2-"
2 | push 2
| implicit print TOS
2” | push the string "2"
-2 | push -2
| implicit print TOS
answered 2 hours ago
GiuseppeGiuseppe
19.3k3 gold badges16 silver badges71 bronze badges
19.3k3 gold badges16 silver badges71 bronze badges
add a comment
|
add a comment
|
1 2
next
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f192979%2fi-reverse-the-source-code-you-negate-the-output%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
@Grimy Oh yeah.
$endgroup$
– TwilightSparkle
8 hours ago
4
$begingroup$
I don't think the
kolmogorov-complexitytag is appropriate, here.$endgroup$
– Grimy
8 hours ago
$begingroup$
@Grimy I simply compied the "I double the source code, you double the output" question, with some minor modification. If it is not appropriate here, I will remove it.
$endgroup$
– TwilightSparkle
8 hours ago
$begingroup$
If we could reverse at the bit level rather than the byte level the one byte
-(0x45 = 0b00101101) works in Jelly --yields -1 since it defines the literal -1, whileṆ(0xB4 = 0b10110100) yields 1 since it performs a logical not of the implicit input of zero. (Of courseṆworks just as well :p)$endgroup$
– Jonathan Allan
49 mins ago