We’re rewarding the question askers & reputations are being recalculated! Read more.

New answers tagged

0

Jelly, 2 bytes &’ Try it online! Just a translation of the accepted JavaScript solution.


1

Wren, 18 17 bytes Umm, it's shorter than GolfScript... Fn.new{|n|n&-n<n} Try it online!


1

Poetic, 190 bytes although i agree i,a person,i was dismissive about a hell,i am not anarchic i repeat:i know theres never a hell i am doomed to actually,it seems a bit of a fraud,a lie,if He gives a man he|l Try it online! Input is in decimal. Output is an Unexpected EOF error for even inputs, and a Mismatched IF/EIF error for odd inputs. It takes ...


2

Shakespeare Programming Language, 137 bytes Try it online! #.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]Ajax:Listen tothy.You is the remainder of the quotient betweenyou a big cat.Open heart Fairly simple, just outputs the input mod 2. Maybe improvable.


0

MarioLANG, 37 bytes ;>-)+([!) ="=====#: )![(-)-< :#=====" Try it online! Outputs 1 for odd and 0 for even.


1

Commodore BASIC (C64/128, VIC-20, TheC64/Mini, C16/+4) - 21 tokenized bytes In this one, odd numbers produce a TRUE value and even numbers produce a FALSE (though on Commodore BASIC, FALSE is zero and TRUE is negative one; it does not do this, more conforms to modern-days TRUE/FALSE integer equivalents) 0 inputa:ifatH?a":"aaN1 Expanded and non-minimised ...


1

RPL, 4 bytes 2MOD Plain answer in vanilla RPL, for posterity and completeness of this thread. As often with RPL, one byte is saved in the source code by removing a space between a number and a command. I assume this is rarely observed in Forth.


2

Bitwise Cyclic Tag, 2 bits (0.25 bytes) With an input of 1 this should either set the data string to a null string or a string of length 2 in its next iteration. 01 Explanation: 0 Delete the leftmost data bit. Halt. No more instructions executed. 1 Not executed Reversed: 1 If the left-most data-bit is 1, 0 Append a 0 to the data-string.


1

SimpleTemplate, 10 bytes This was actually hard to optimize, without going into the trivial answer. {@echo"1"} Outputs the string "1". When reversing, you get the following: }"1"ohce@{ Outputs the string }"1"ohce@{. As stated in the question: "The output can be any two distinct values, of the same data type.", and both solutions output a distinct ...


0

Excuse my rusty Ruby. Maybe someone can hint how to shorten. :) Ruby, 163 bytes s=0;ARGV[0].split(",").zip(ARGV[2].split(",")).map{|a,b|b.to_i-a.to_i}.zip( ARGV[1].split(",").zip(ARGV[3].split(",")).map{|a,b|b.to_i-a.to_i}){|a,b|s+=a*b};p s==0 Try it online!


4

JavaScript (ES6), 219 bytes Takes input as a list of lists of characters. a=>((g=(X,Y,D,n=o=0)=>!(a+0)[n++]|a.some((r,y)=>r.some((c,x)=>D=='975'[i='-| #+$'.indexOf(c),x-X+1]-'450'[y-Y+1]?i-3?i-2?i>3?[3,0,7,4].some(d=>D^d^4&&g(x,y,d,n)):~i&&i^D&1?0:g(x,y,D,n):0:o=-n:X+1|i<5?0:g(x,y,2))))(),~o) Try it online! How? ...


1

Pyth, 12 bytes qhQeo+*6hNeN Try it online! Pretty simple but Im happy with it. Takes (g1,b1),(g2,b2), returns True or False How it works qhQeo+*6hNeN qhQ - The first input is equal to.. eo - The last input of a sorted list (implicitly the input) +*6hNeN - With the key 6 * first (hN) + last (eN)


1

R, 28 bytes function(a,b,c,d)a*6+b>c*6+d Try it online!


2

Poetic, 751 bytes the game:a game o soccer for a moment of my fun,i kicked my leg o,i hurt a player o.m.gee,o no suddenly i then apologized a little o.m.gee,o no but really,i loved a good soccer battle a game i am doing,i love it there is a game,a twenty-to-one unwinnable match(as we called it,i mean)a match we won a wonder of an event i saw i played,i go ...


3

Haskell, 52 bytes a=0-- --b tnirp=b#a niam=main 1#a=niam main=print a ==> prints "1" a tnirp=niam main=a#1 niam=main a#b=print b-- --0=a ==> prints "0" Explanation: a=0-- -- FWD: define constant "a" to be 0 / BWD: No-op -- --b tnirp=b#a -- FWD: No-op / BWD: define a function "#" in two arguments and prints the -- -...


1

Java, 14 bytes ()->1;//;0>-)( Simple program that uses comments to exclude the other part. Outputs 1, and reversed outputs 0.


2

TI-BASIC Non-trivial, 4 5 bytes Disp "Disp : This outputs 'Disp :' Since TI-BASIC is token based, reversing it gives :Disp "Disp which outputs 'Disp' Let me explain. 'Disp ' is one token which prints the given string to the home screen. First we are giving it a string of 'Disp :', so simple there. When reversed, since each 'Disp ' is one byte, we ...


1

Whitespace, 20 bytes S S S 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 0/-1. Try it online or try it online reversed (with raw spaces, tabs and new-lines only). Explanation: Very minor modification of my answer here (outputting 0 is 1 byte shorter than 1), so I'm just ...


2

Deadfish~, 2 bytes oi Try it online! Boy, if that fruit hanged any lower, it'd be underground I tell you.


3

Poetic, 15 13 bytes tis,A NAMETAG Try it online! Prints ASCII character 1 (SOH). GATEMAN A,sit Try it online! Prints ASCII character 0 (NUL). The previous answer ends with an "Unexpected EOF" error forwards because the END command (any ten-letter word) is omitted, and a "Mismatched IF/EIF" error backwards because EOF is encountered before an IF/EIF ...


0

Triangular, 3 bytes i.% Try it online! Prints 1. %.i prints 0. If it weren't invalid to do an integer and a character, %# would've been a nice 2-byter.


0

SmileBASIC, 4 bytes ?12? prints 12\n\n forwards and 21\n\n backwards


2

MarioLANG, 3 bytes : + Try it online! Prints 0 + : Try it online! Prints 1 MarioLANG, 10 bytes == :+ == Try it online! Prints 0 == +: == Try it online! Prints 1


2

PowerShell, 56 55 54 47 bytes inspired by Arnauld's one accumulator code. !($args+1|?{$_;$t+=$_-1}|?{$t-ge$_;$t*=$t-ge0}) Try it online!


1

J, 28 bytes [:*/1>1&,*([0&>.<:@+)/\.@,&0 Try it online! Inspired by Arnauld's algorithm. 1 if a solution exists, 0 otherwise. How it works In order to retain intermediate values of t, I chose to use "Reduce on suffixes" /\. with the initial value appended. Given a function f, the result of f/\. looks like this: Input array: 0 0 2 2 ...


1

Jelly, 20 bytes ŒṖT€ẈỊẠƲƇðẈẋ`€F⁹a⁼ðƇ A monadic Link accepting a list of non-negative integers which yields a list. An empty list is falsey, a non-empty list is truthy. (The list is actually all ways which work). Try it online! Or see a test-suite. How? ŒṖT€ẈỊẠƲƇðẈẋ`€F⁹a⁼ðƇ - Link: list, S ŒṖ - all partitions (of S) Ƈ ...


2

HolyC, 12 bytes Like the C version, except using the implicit print in HolyC "0"; // ;"1" Prints 0 "1"; // ;"0" Prints 1 Spaces required by the compiler :)


1

Rebol, 2 bytes #1 Prints #1 1# Prints ##


2

POSIX sh (Dash, Bash, Zsh, ...), 3 bytes : ! Try it online! The builtin : discards its arguments and exits 0 (true). Reversed, ! negates the exit code of : and exits 1 (false).


5

bash, 12 bytes (no comments or string literals) echo 0$ ohce Prints "0$ ohce" echo $0 ohce Prints "bash ohce" bash, 11 bytes (no comments or string literals) echo ftnirp Prints "ftnirp" printf ohce Prints "ohce"


1

Runic Enchantments, 3 bytes 0@1 Try it online! Prints 0 forwards and 1 backwards. If no output is allowed, then @1 saves a byte.


1

Keg, 165 bytes (SBCS) ¿®w?(: =[_]")0®u(!4/|\0-&:B=[&3*&|:C=[&55**&|:G=[&2*&|:K=[&\2*&|&15/*&]]]]__:b=[&1*&|:e=[&0&|:h=[&2*&|:j=[&0&|:r=[&6*&|:t=[&7*&|:v=[&6*&|&3*&]]]]]]]_©u&+®u)©w2/:©u<. Try it online! I feel as if though a Keg answer has ...


4

R, 2 bytes .1 Prints 0.1. 1. Prints 1. Both numeric (double). tio Less trivial? and for an explicit true/false 2>1 # TRUE 1>2 # FALSE tio


1

J, 47 bytes [:*/2(>+.0>:[)/\[:(++(0>.0-+)*0<+-])/@|.\<:@,&1 Try it online! Credit to Arnauld for the high-level idea. I'll add explanation and golf more soon.


4

Wolfram Language (Mathematica), 10 bytes Print@ohcE Try it online! Prints ohcE. Echo@tnirP Try it online! Prints >> tnirP.


2

Befunge-98 (PyFunge), 2 bytes @, Try it online! Prints nothing by default, prints a null byte if reversed


1

C (gcc), 21 bytes puts("");//;)"0"(stup Try it online! !enilno ti yrT


2

Turing Machine Code, no comments or string literals, 19 bytes 0 * 0 * 0 0 * 1 * 0 Reversed: 0 * 1 * 0 0 * 0 * 0 Try it online! The code runs without errors, but does loop forever. Prints '0' forward, prints '1' reversed.


2

MathGolf, 2 bytes This one does not have any nilads or dyads inside the program. Just monads. ±( Try it online! Explanation ± Find absolute value of the implicit 0 ( Decrement 0, resulting -1. Reversed: ( Decrement 0, resulting -1. ± Find absolute value of -1, which results in 1.


2

Ceylon (Snippet), 20 The same trivial thing as in many other languages: print(1);//;)2(tnirp Outputs 1. print(2);//;)1(tnirp Outputs 2. Given that parentheses need to be in the right order and you need print for output, I don't think this can be improved. A full program or function needs even more braces/parentheses mirrored, so no chance of getting ...


1

PHP, 2 bytes 12 Try it online! Prints 12 ... 21 Try it online! Prints 21 ... Looking for non-trivial solution? PHP, 11 bytes <?=1;#;2=?< Try it online! Prints 1 ... <?=2;#;1=?< Try it online! Prints 2 ... Don't like comment abuse? PHP, 13 bytes ;echo+1-ohce; Try it online! Prints 1 ... ;echo-1+ohce; Try it online! Prints -1 ....


1

Wolfram Language (Mathematica), 41 35 34 bytes Norm@Cos@PolygonAngle@Polygon@#>0& Returns False for rectilinear polygons and True otherwise. Only works in 12.0+, so no TIO link -6 bytes thanks to @Roman -1 bytes thanks to deleted comment


2

Ruby, 6 bytes p:stup Output :stup Reversed output p


60

Python 3, no comments or string literals, 106 bytes x=quit y=x.__class__ y.__add__=print y.__pos__=x x+x++x+x x=__sop__.y tnirp=__dda__.y __ssalc__.x=y tixe=x I've never liked how comments and string literals let you "turn off" most of your language's syntax in challenges like this, so I wanted to see how far I could golf things without using either ...


1

Japt, 2 bytes c1 Return x rounded up to nearest multiple of N => output 0 Test it 1c x default to 1 => output 1 Test it


3

Perl 5, 11 bytes say$-,$$yas Try it online! Outputs 0 when run forward. Outputs the current process number followed by 0 when run backwards.


2

brainf*** 2 bytes +. Try it online! Outputs 1 forwards, 0 backwards. Really randomdude999's answer


3

Actually, 2 bytes Decrement empty value & push 1. D1 Reversed program decrements 1, outputting 0. 1D Try it online! 05AB1E, 2 bytes The exact same answer ported to a different language. <1 Try it online!


2

05AB1E, 2 bytes Push 1 onto the stack & negates. (This results in -1) 1( Negate empty value & push 1. Output 1 implicitly. (1 Try it online!


2

Wren, 32 bytes Basically just a port of the Python answer. System.write(1)//)0(etirw.metsyS Try it online!


Top 50 recent answers are included