29
\$\begingroup\$

Yet another blatant rip-off of a rip-off of a rip-off. Go upvote those!

Your task, if you wish to accept it, is to write a program/function that outputs/returns its string input/argument. The tricky part is that if I reverse your source code, the output must be reversed too.

For simplicity, you can assume that the input is always a single line string containing only ASCII letters (a-z), digits (0-9) and spaces.

Should support an input of at least 8 characters long (longer than 8 is not necessary).

Behaviour for empty input is undefined.

Examples

Let's say your source code is ABC and its input is xyz. If I write CBA instead and run it, the output must be zyx.

Let's say your source code is ABC and its input is 96. If I write CBA instead and run it, the output must be 69.

A single leading or trailing white-space is acceptable as long as it is consistent in both normal and reversed outputs.

\$\endgroup\$
0

44 Answers 44

23
\$\begingroup\$

JavaScript, 32 bytes

s=>s//``nioj.)(esrever.]s...[>=s

Reversed:

s=>[...s].reverse().join``//s>=s
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Well done, didn't know JS doesn't have a builtin reverse for strings. By the way, TIO links usually make answers more likable: Try it online! Reversed \$\endgroup\$
    – Night2
    Commented Sep 22, 2019 at 14:12
  • 4
    \$\begingroup\$ There is no string reverse. [...s] converts to array, which is reversed then joined back together as a string. \$\endgroup\$
    – James
    Commented Sep 22, 2019 at 14:59
  • \$\begingroup\$ If you also stumbled over .join`` - have a look at Tagged Templates \$\endgroup\$
    – nitzel
    Commented Sep 23, 2019 at 9:37
17
\$\begingroup\$

Bash, 9 bytes

cat # ver

Reversed:

rev # tac

Try it online! !enilno ti yrT

\$\endgroup\$
1
  • 7
    \$\begingroup\$ This would be easier if the challenge was to reverse the line order; then I could just use cat. \$\endgroup\$
    – S.S. Anne
    Commented Sep 23, 2019 at 11:43
17
\$\begingroup\$

APL (Dyalog Unicode), 3 2 bytesSBCS

-1 byte thanks to dzaima

⌽⊂

Try it online!

 enclose the argument to treat it as a singleton: [1,2,3][[1,2,3]]

 reverse (has no effect on singletons): [[1,2,3]][[1,2,3]]

An enclosed array prints with a leading an a trailing space.

!enilno ti yrT

 reverse (has no effect on singletons): [1,2,3][3,2,1]

 enclose: [3,2,1][[3,2,1]]

An enclosed array prints with a leading an a trailing space.

\$\endgroup\$
11
  • \$\begingroup\$ Nice. Digraphs make this more difficult in J... haven’t come up with anything yet \$\endgroup\$
    – Jonah
    Commented Sep 22, 2019 at 15:31
  • \$\begingroup\$ I was pretty happy with my 5 byte solution, but yours is so elegant. {⍵⋄⍵⌽⊢} \$\endgroup\$ Commented Mar 31, 2021 at 20:57
  • \$\begingroup\$ @AndrewOgden That wouldn't work though, as the reverse is }⊢⌽⍵⋄⍵{ \$\endgroup\$
    – Adám
    Commented Mar 31, 2021 at 21:00
  • \$\begingroup\$ @Adám Lol, I was so focused on the stuff inside the brackets, I completely forgot that they also needed reversing. \$\endgroup\$ Commented Mar 31, 2021 at 21:31
  • \$\begingroup\$ @AndrewOgden Tacit is the way to go. A more "correct" solution would be ⌽⊢⊢ \$\endgroup\$
    – Adám
    Commented Mar 31, 2021 at 21:32
11
\$\begingroup\$

Keg, 3 2 bytes

#?

Try it online! or !enilno ti yrT

Explained

#? #Implicit cat
?# Reversed input

Heh. That's right. Keg can stand up to those 2-byte answers too (and using pure, plain ASCII)!

Old Program

^#?

Try it online! Or !enilno ti yrT

Because two can play the 3-byte game. That's why. (did I mention that's 3 bytes of utf8 ASCII?)

^#? #Reverse an empty stack, taking implicit input

?#^ #take input
\$\endgroup\$
1
  • \$\begingroup\$ interpreter where \$\endgroup\$
    – ASCII-only
    Commented Feb 27, 2020 at 11:26
9
\$\begingroup\$

Ruby, 21 bytes

->x{x}#}esrever.x{x>-

Try it online!

->x{x.reverse}#}x{x>-

!enilno ti yrT

\$\endgroup\$
8
\$\begingroup\$

Stack Cats -m, 4 bytes

|>I|

Try it online!

Try it reversed!

This works for any inputs that don't contain null bytes.

Explanation

Wow, I've reached the point where I'm writing these by hand...

The full program is |>I|I<|.

|   Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
>   Move one stack over to the right (which only contains zeros).
I   Does nothing on zero.
|   Does nothing on zero.
I   Does nothing on zero.
<   Move back to the initial stack.
|   Reverse the input once more.

As in the solution to the previous challenge, since the centre command | does nothing, so does the entire program.

The reversed program is then |I>|<I|.

|   Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
I   Move the -1 one stack to the left and turn it into a +1.
>   Move back to the initial stack.
|   Reverse it again, but this time without the EOF marker.
<   Move back to the left.
I   Move the +1 back onto the initial stack and turn it into a -1 again.
|   Reverse the entire stack. We now have the -1 as an EOF marker again at the bottom
    and the rest of the stack has been reversed three times, i.e. one net reversal.

Interestingly, if we use this reversing program without -m we still get a working solution this time, so the only additional bytes incurred by omitting -m are those we get from mirroring the code.


Stack Cats, 7 bytes

|I<|>I|

Try it online!

Try it reversed!

Explanation

The reversed version of this program is |I>|<I|, the same as above so we can ignore that. But the non-reversed version differs. Since the <> now point the other way, the centre command ends up doing nothing, so the program becomes a cat:

|   Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
I   Move the -1 one stack to the left and turn it into a +1.
<   Move another stack to the left, which contains only zeros.
|   Does nothing on zero.

And thus, >I| exactly undo the first half of the program.

\$\endgroup\$
7
\$\begingroup\$

Haskell, 11 bytes

id--esrever

Try it online! Try it reversed!

\$\endgroup\$
7
\$\begingroup\$

Pyth, 5 3 bytes

z_k

-2 bytes by realizing the newline flips around anyways

Explanation:

z   # Implicitly print the input
 _k # Implicitly print the reversed empty string

Reversed Explanation:

k     # Implicitly print the empty string
 _z   # Implicitly print the reversed input
\$\endgroup\$
6
\$\begingroup\$

Turing Machine Language, 14324 14321 13257 bytes

0 ( ( l 6;
0 * * l 2;
1 _ _ l 2;
2 _ ( r 3;
3 _ _ r 4;
4 _ _ l 3);
4 * * r 2;
3) _ ) l 5;
3 * * r 3;
5 ( ( * 0;
5 * * l 5;
6 _ _ l 7;
7 _ ] r 8;
8 ) ) l 9;
8 * * r 8;
9 0 @ l c0;
9 1 @ l c1;
9 2 @ l c2;
9 3 @ l c3;
9 4 @ l c4;
9 5 @ l c5;
9 6 @ l c6;
9 7 @ l c7;
9 8 @ l c8;
9 9 @ l c9;
9 a @ l a;
9 A @ l A;
9 b @ l b;
9 B @ l B;
9 c @ l c;
9 C @ l C;
9 d @ l d;
9 D @ l D;
9 e @ l e;
9 E @ l E;
9 f @ l f;
9 F @ l F;
9 g @ l g;
9 G @ l G;
9 h @ l h;
9 H @ l H;
9 i @ l i;
9 I @ l I;
9 j @ l j;
9 J @ l J;
9 k @ l k;
9 K @ l K;
9 l @ l l;
9 L @ l L;
9 m @ l m;
9 M @ l M;
9 n @ l n;
9 N @ l N;
9 o @ l o;
9 O @ l O;
9 p @ l p;
9 P @ l P;
9 q @ l q;
9 Q @ l Q;
9 r @ l r;
9 R @ l R;
9 s @ l s;
9 S @ l S;
9 t @ l t;
9 T @ l T;
9 u @ l u;
9 U @ l U;
9 v @ l v;
9 V @ l V;
9 w @ l w;
9 W @ l W;
9 x @ l x;
9 X @ l X;
9 y @ l y;
9 Y @ l Y;
9 z @ l z;
9 Z @ l Z;
c0 ] ] l c0a;
c0 * * l c0;
c0a _ 0 r @0;
c0a * * l c0a;
@0 @ 0 l nC;
@0 * * r @0;
c1 ] ] l c1a;
c1 * * l c1;
c1a _ 1 r @1;
c1a * * l c1a;
@1 @ 1 l nC;
@1 * * r @1;
c2 ] ] l c2a;
c2 * * l c2;
c2a _ 2 r @2;
c2a * * l c2a;
@2 @ 2 l nC;
@2 * * r @2;
c3 ] ] l c3a;
c3 * * l c3;
c3a _ 3 r @3;
c3a * * l c3a;
@3 @ 3 l nC;
@3 * * r @3;
c4 ] ] l c4a;
c4 * * l c4;
c4a _ 4 r @4;
c4a * * l c4a;
@4 @ 4 l nC;
@4 * * r @4;
c5 ] ] l c5a;
c5 * * l c5;
c5a _ 5 r @5;
c5a * * l c5a;
@5 @ 5 l nC;
@5 * * r @5;
c6 ] ] l c6a;
c6 * * l c6;
c6a _ 6 r @6;
c6a * * l c6a;
@6 @ 6 l nC;
@6 * * r @6;
c7 ] ] l c7a;
c7 * * l c7;
c7a _ 7 r @7;
c7a * * l c7a;
@7 @ 7 l nC;
@7 * * r @7;
c8 ] ] l c8a;
c8 * * l c8;
c8a _ 8 r @8;
c8a * * l c8a;
@8 @ 8 l nC;
@8 * * r @8;
c9 ] ] l c9a;
c9 * * l c9;
c9a _ 9 r @9;
c9a * * l c9a;
@9 @ 9 l nC;
@9 * * r @9;
a ] ] l aa;
a * * l a;
aa _ a r @a;
aa * * l aa;
@a @ a l nC;
@a * * r @a;
A ] ] l Aa;
A * * l A;
Aa _ A r @A;
Aa * * l Aa;
@A @ A l nC;
@A * * r @A;
b ] ] l ba;
b * * l b;
ba _ b r @b;
ba * * l ba;
@b @ b l nC;
@b * * r @b;
B ] ] l Ba;
B * * l B;
Ba _ B r @B;
Ba * * l Ba;
@B @ B l nC;
@B * * r @B;
c ] ] l ca;
c * * l c;
ca _ c r @c;
ca * * l ca;
@c @ c l nC;
@c * * r @c;
C ] ] l Ca;
C * * l C;
Ca _ C r @C;
Ca * * l Ca;
@C @ C l nC;
@C * * r @C;
d ] ] l da;
d * * l d;
da _ d r @d;
da * * l da;
@d @ d l nC;
@d * * r @d;
D ] ] l Da;
D * * l D;
Da _ D r @D;
Da * * l Da;
@D @ D l nC;
@D * * r @D;
e ] ] l ea;
e * * l e;
ea _ e r @e;
ea * * l ea;
@e @ e l nC;
@e * * r @e;
E ] ] l Ea;
E * * l E;
Ea _ E r @E;
Ea * * l Ea;
@E @ E l nC;
@E * * r @E;
f ] ] l fa;
f * * l f;
fa _ f r @f;
fa * * l fa;
@f @ f l nC;
@f * * r @f;
F ] ] l Fa;
F * * l F;
Fa _ F r @F;
Fa * * l Fa;
@F @ F l nC;
@F * * r @F;
g ] ] l ga;
g * * l g;
ga _ g r @g;
ga * * l ga;
@g @ g l nC;
@g * * r @g;
G ] ] l Ga;
G * * l G;
Ga _ G r @G;
Ga * * l Ga;
@G @ G l nC;
@G * * r @G;
h ] ] l ha;
h * * l h;
ha _ h r @h;
ha * * l ha;
@h @ h l nC;
@h * * r @h;
H ] ] l Ha;
H * * l H;
Ha _ H r @H;
Ha * * l Ha;
@H @ H l nC;
@H * * r @H;
i ] ] l ia;
i * * l i;
ia _ i r @i;
ia * * l ia;
@i @ i l nC;
@i * * r @i;
I ] ] l Ia;
I * * l I;
Ia _ I r @I;
Ia * * l Ia;
@I @ I l nC;
@I * * r @I;
j ] ] l ja;
j * * l j;
ja _ j r @j;
ja * * l ja;
@j @ j l nC;
@j * * r @j;
J ] ] l Ja;
J * * l J;
Ja _ J r @J;
Ja * * l Ja;
@J @ J l nC;
@J * * r @J;
k ] ] l ka;
k * * l k;
ka _ k r @k;
ka * * l ka;
@k @ k l nC;
@k * * r @k;
K ] ] l Ka;
K * * l K;
Ka _ K r @K;
Ka * * l Ka;
@K @ K l nC;
@K * * r @K;
l ] ] l la;
l * * l l;
la _ l r @l;
la * * l la;
@l @ l l nC;
@l * * r @l;
L ] ] l La;
L * * l L;
La _ L r @L;
La * * l La;
@L @ L l nC;
@L * * r @L;
m ] ] l ma;
m * * l m;
ma _ m r @m;
ma * * l ma;
@m @ m l nC;
@m * * r @m;
M ] ] l Ma;
M * * l M;
Ma _ M r @M;
Ma * * l Ma;
@M @ M l nC;
@M * * r @M;
n ] ] l na;
n * * l n;
na _ n r @n;
na * * l na;
@n @ n l nC;
@n * * r @n;
N ] ] l Na;
N * * l N;
Na _ N r @N;
Na * * l Na;
@N @ N l nC;
@N * * r @N;
o ] ] l oa;
o * * l o;
oa _ o r @o;
oa * * l oa;
@o @ o l nC;
@o * * r @o;
O ] ] l Oa;
O * * l O;
Oa _ O r @O;
Oa * * l Oa;
@O @ O l nC;
@O * * r @O;
p ] ] l pa;
p * * l p;
pa _ p r @p;
pa * * l pa;
@p @ p l nC;
@p * * r @p;
P ] ] l Pa;
P * * l P;
Pa _ P r @P;
Pa * * l Pa;
@P @ P l nC;
@P * * r @P;
q ] ] l qa;
q * * l q;
qa _ q r @q;
qa * * l qa;
@q @ q l nC;
@q * * r @q;
Q ] ] l Qa;
Q * * l Q;
Qa _ Q r @Q;
Qa * * l Qa;
@Q @ Q l nC;
@Q * * r @Q;
r ] ] l ra;
r * * l r;
ra _ r r @r;
ra * * l ra;
@r @ r l nC;
@r * * r @r;
R ] ] l Ra;
R * * l R;
Ra _ R r @R;
Ra * * l Ra;
@R @ R l nC;
@R * * r @R;
s ] ] l sa;
s * * l s;
sa _ s r @s;
sa * * l sa;
@s @ s l nC;
@s * * r @s;
S ] ] l Sa;
S * * l S;
Sa _ S r @S;
Sa * * l Sa;
@S @ S l nC;
@S * * r @S;
t ] ] l ta;
t * * l t;
ta _ t r @t;
ta * * l ta;
@t @ t l nC;
@t * * r @t;
T ] ] l Ta;
T * * l T;
Ta _ T r @T;
Ta * * l Ta;
@T @ T l nC;
@T * * r @T;
u ] ] l ua;
u * * l u;
ua _ u r @u;
ua * * l ua;
@u @ u l nC;
@u * * r @u;
U ] ] l Ua;
U * * l U;
Ua _ U r @U;
Ua * * l Ua;
@U @ U l nC;
@U * * r @U;
v ] ] l va;
v * * l v;
va _ v r @v;
va * * l va;
@v @ v l nC;
@v * * r @v;
V ] ] l Va;
V * * l V;
Va _ V r @V;
Va * * l Va;
@V @ V l nC;
@V * * r @V;
w ] ] l wa;
w * * l w;
wa _ w r @w;
wa * * l wa;
@w @ w l nC;
@w * * r @w;
W ] ] l Wa;
W * * l W;
Wa _ W r @W;
Wa * * l Wa;
@W @ W l nC;
@W * * r @W;
x ] ] l xa;
x * * l x;
xa _ x r @x;
xa * * l xa;
@x @ x l nC;
@x * * r @x;
X ] ] l Xa;
X * * l X;
Xa _ X r @X;
Xa * * l Xa;
@X @ X l nC;
@X * * r @X;
y ] ] l ya;
y * * l y;
ya _ y r @y;
ya * * l ya;
@y @ y l nC;
@y * * r @y;
Y ] ] l Ya;
Y * * l Y;
Ya _ Y r @Y;
Ya * * l Ya;
@Y @ Y l nC;
@Y * * r @Y;
z ] ] l za;
z * * l z;
za _ z r @z;
za * * l za;
@z @ z l nC;
@z * * r @z;
Z ] ] l Za;
Z * * l Z;
Za _ Z r @Z;
Za * * l Za;
@Z @ Z l nC;
@Z * * r @Z;
Sp ] ] l Sp1;
Sp * * l Sp;
Sp1 _ ~ r @Sp;
Sp1 * * l Sp1;
@Sp @ _ l nC;
@Sp * * r @Sp;
nC _ @ l Sp;
nC 0 0 * 9;
nC 1 1 * 9;
nC 2 2 * 9;
nC 3 3 * 9;
nC 4 4 * 9;
nC 5 5 * 9;
nC 6 6 * 9;
nC 7 7 * 9;
nC 8 8 * 9;
nC 9 9 * 9;
nC - - * 9;
nC a a * 9;
nC A A * 9;
nC b b * 9;
nC B B * 9;
nC c c * 9;
nC C C * 9;
nC d d * 9;
nC D D * 9;
nC e e * 9;
nC E E * 9;
nC f f * 9;
nC F F * 9;
nC g g * 9;
nC G G * 9;
nC h h * 9;
nC H H * 9;
nC i i * 9;
nC I I * 9;
nC j j * 9;
nC J J * 9;
nC k k * 9;
nC K K * 9;
nC l l * 9;
nC L L * 9;
nC m m * 9;
nC M M * 9;
nC n n * 9;
nC N N * 9;
nC o o * 9;
nC O O * 9;
nC p p * 9;
nC P P * 9;
nC q q * 9;
nC Q Q * 9;
nC r r * 9;
nC R R * 9;
nC s s * 9;
nC S S * 9;
nC t t * 9;
nC T T * 9;
nC u u * 9;
nC U U * 9;
nC v v * 9;
nC V V * 9;
nC w w * 9;
nC W W * 9;
nC x x * 9;
nC X X * 9;
nC y y * 9;
nC Y Y * 9;
nC z z * 9;
nC Z Z * 9;
nC ( ( * fC;
fC ] ] l fC1;
fC * * l fC;
fC1 _ [ * cl;
fC1 * * l fC1;
cl [ _ r cl;
cl ] _ r cl;
cl ~ _ r cl;
cl ( _ r clO;
clO ) _ * halt-accept;
clO * _ r clO;
cl ) ) * halt-accept;
cl * * r cl;
;lc r * * lc
;tpecca-tlah * ) ) lc
;Olc r _ * Olc
;tpecca-tlah * _ ) Olc
;Olc r _ ( lc
;lc r _ ~ lc
;lc r _ ] lc
;lc r _ [ lc
;1Cf l * * 1Cf
;lc * [ _ 1Cf
;Cf l * * Cf
;1Cf l ] ] Cf
;Cf * ) ) Cn
;9 * Z Z Cn
;9 * z z Cn
;9 * Y Y Cn
;9 * y y Cn
;9 * X X Cn
;9 * x x Cn
;9 * W W Cn
;9 * w w Cn
;9 * V V Cn
;9 * v v Cn
;9 * U U Cn
;9 * u u Cn
;9 * T T Cn
;9 * t t Cn
;9 * S S Cn
;9 * s s Cn
;9 * R R Cn
;9 * r r Cn
;9 * Q Q Cn
;9 * q q Cn
;9 * P P Cn
;9 * p p Cn
;9 * O O Cn
;9 * o o Cn
;9 * N N Cn
;9 * n n Cn
;9 * M M Cn
;9 * m m Cn
;9 * L L Cn
;9 * l l Cn
;9 * K K Cn
;9 * k k Cn
;9 * J J Cn
;9 * j j Cn
;9 * I I Cn
;9 * i i Cn
;9 * H H Cn
;9 * h h Cn
;9 * G G Cn
;9 * g g Cn
;9 * F F Cn
;9 * f f Cn
;9 * E E Cn
;9 * e e Cn
;9 * D D Cn
;9 * d d Cn
;9 * C C Cn
;9 * c c Cn
;9 * B B Cn
;9 * b b Cn
;9 * A A Cn
;9 * a a Cn
;9 * - - Cn
;9 * 9 9 Cn
;9 * 8 8 Cn
;9 * 7 7 Cn
;9 * 6 6 Cn
;9 * 5 5 Cn
;9 * 4 4 Cn
;9 * 3 3 Cn
;9 * 2 2 Cn
;9 * 1 1 Cn
;9 * 0 0 Cn
;pS l @ _ Cn
;pS@ r * * pS@
;Cn r _ @ pS@
;1pS l * * 1pS
;pS@ r ~ _ 1pS
;pS l * * pS
;1pS l ] ] pS
;Z@ r * * Z@
;Cn r Z @ Z@
;aZ l * * aZ
;Z@ r Z _ aZ
;Z l * * Z
;aZ l ] ] Z
;z@ r * * z@
;Cn r z @ z@
;az l * * az
;z@ r z _ az
;z l * * z
;az l ] ] z
;Y@ r * * Y@
;Cn r Y @ Y@
;aY l * * aY
;Y@ r Y _ aY
;Y l * * Y
;aY l ] ] Y
;y@ r * * y@
;Cn r y @ y@
;ay l * * ay
;y@ r y _ ay
;y l * * y
;ay l ] ] y
;X@ r * * X@
;Cn r X @ X@
;aX l * * aX
;X@ r X _ aX
;X l * * X
;aX l ] ] X
;x@ r * * x@
;Cn r x @ x@
;ax l * * ax
;x@ r x _ ax
;x l * * x
;ax l ] ] x
;W@ r * * W@
;Cn r W @ W@
;aW l * * aW
;W@ r W _ aW
;W l * * W
;aW l ] ] W
;w@ r * * w@
;Cn r w @ w@
;aw l * * aw
;w@ r w _ aw
;w l * * w
;aw l ] ] w
;V@ r * * V@
;Cn r V @ V@
;aV l * * aV
;V@ r V _ aV
;V l * * V
;aV l ] ] V
;v@ r * * v@
;Cn r v @ v@
;av l * * av
;v@ r v _ av
;v l * * v
;av l ] ] v
;U@ r * * U@
;Cn r U @ U@
;aU l * * aU
;U@ r U _ aU
;U l * * U
;aU l ] ] U
;u@ r * * u@
;Cn r u @ u@
;au l * * au
;u@ r u _ au
;u l * * u
;au l ] ] u
;T@ r * * T@
;Cn r T @ T@
;aT l * * aT
;T@ r T _ aT
;T l * * T
;aT l ] ] T
;t@ r * * t@
;Cn r t @ t@
;at l * * at
;t@ r t _ at
;t l * * t
;at l ] ] t
;S@ r * * S@
;Cn r S @ S@
;aS l * * aS
;S@ r S _ aS
;S l * * S
;aS l ] ] S
;s@ r * * s@
;Cn r s @ s@
;as l * * as
;s@ r s _ as
;s l * * s
;as l ] ] s
;R@ r * * R@
;Cn r R @ R@
;aR l * * aR
;R@ r R _ aR
;R l * * R
;aR l ] ] R
;r@ r * * r@
;Cn r r @ r@
;ar l * * ar
;r@ r r _ ar
;r l * * r
;ar l ] ] r
;Q@ r * * Q@
;Cn r Q @ Q@
;aQ l * * aQ
;Q@ r Q _ aQ
;Q l * * Q
;aQ l ] ] Q
;q@ r * * q@
;Cn r q @ q@
;aq l * * aq
;q@ r q _ aq
;q l * * q
;aq l ] ] q
;P@ r * * P@
;Cn r P @ P@
;aP l * * aP
;P@ r P _ aP
;P l * * P
;aP l ] ] P
;p@ r * * p@
;Cn r p @ p@
;ap l * * ap
;p@ r p _ ap
;p l * * p
;ap l ] ] p
;O@ r * * O@
;Cn r O @ O@
;aO l * * aO
;O@ r O _ aO
;O l * * O
;aO l ] ] O
;o@ r * * o@
;Cn r o @ o@
;ao l * * ao
;o@ r o _ ao
;o l * * o
;ao l ] ] o
;N@ r * * N@
;Cn r N @ N@
;aN l * * aN
;N@ r N _ aN
;N l * * N
;aN l ] ] N
;n@ r * * n@
;Cn r n @ n@
;an l * * an
;n@ r n _ an
;n l * * n
;an l ] ] n
;M@ r * * M@
;Cn r M @ M@
;aM l * * aM
;M@ r M _ aM
;M l * * M
;aM l ] ] M
;m@ r * * m@
;Cn r m @ m@
;am l * * am
;m@ r m _ am
;m l * * m
;am l ] ] m
;L@ r * * L@
;Cn r L @ L@
;aL l * * aL
;L@ r L _ aL
;L l * * L
;aL l ] ] L
;l@ r * * l@
;Cn r l @ l@
;al l * * al
;l@ r l _ al
;l l * * l
;al l ] ] l
;K@ r * * K@
;Cn r K @ K@
;aK l * * aK
;K@ r K _ aK
;K l * * K
;aK l ] ] K
;k@ r * * k@
;Cn r k @ k@
;ak l * * ak
;k@ r k _ ak
;k l * * k
;ak l ] ] k
;J@ r * * J@
;Cn r J @ J@
;aJ l * * aJ
;J@ r J _ aJ
;J l * * J
;aJ l ] ] J
;j@ r * * j@
;Cn r j @ j@
;aj l * * aj
;j@ r j _ aj
;j l * * j
;aj l ] ] j
;I@ r * * I@
;Cn r I @ I@
;aI l * * aI
;I@ r I _ aI
;I l * * I
;aI l ] ] I
;i@ r * * i@
;Cn r i @ i@
;ai l * * ai
;i@ r i _ ai
;i l * * i
;ai l ] ] i
;H@ r * * H@
;Cn r H @ H@
;aH l * * aH
;H@ r H _ aH
;H l * * H
;aH l ] ] H
;h@ r * * h@
;Cn r h @ h@
;ah l * * ah
;h@ r h _ ah
;h l * * h
;ah l ] ] h
;G@ r * * G@
;Cn r G @ G@
;aG l * * aG
;G@ r G _ aG
;G l * * G
;aG l ] ] G
;g@ r * * g@
;Cn r g @ g@
;ag l * * ag
;g@ r g _ ag
;g l * * g
;ag l ] ] g
;F@ r * * F@
;Cn r F @ F@
;aF l * * aF
;F@ r F _ aF
;F l * * F
;aF l ] ] F
;f@ r * * f@
;Cn r f @ f@
;af l * * af
;f@ r f _ af
;f l * * f
;af l ] ] f
;E@ r * * E@
;Cn r E @ E@
;aE l * * aE
;E@ r E _ aE
;E l * * E
;aE l ] ] E
;e@ r * * e@
;Cn r e @ e@
;ae l * * ae
;e@ r e _ ae
;e l * * e
;ae l ] ] e
;D@ r * * D@
;Cn r D @ D@
;aD l * * aD
;D@ r D _ aD
;D l * * D
;aD l ] ] D
;d@ r * * d@
;Cn r d @ d@
;ad l * * ad
;d@ r d _ ad
;d l * * d
;ad l ] ] d
;C@ r * * C@
;Cn r C @ C@
;aC l * * aC
;C@ r C _ aC
;C l * * C
;aC l ] ] C
;c@ r * * c@
;Cn r c @ c@
;ac l * * ac
;c@ r c _ ac
;c l * * c
;ac l ] ] c
;B@ r * * B@
;Cn r B @ B@
;aB l * * aB
;B@ r B _ aB
;B l * * B
;aB l ] ] B
;b@ r * * b@
;Cn r b @ b@
;ab l * * ab
;b@ r b _ ab
;b l * * b
;ab l ] ] b
;A@ r * * A@
;Cn r A @ A@
;aA l * * aA
;A@ r A _ aA
;A l * * A
;aA l ] ] A
;a@ r * * a@
;Cn r a @ a@
;aa l * * aa
;a@ r a _ aa
;a l * * a
;aa l ] ] a
;9@ r * * 9@
;Cn r 9 @ 9@
;a9c l * * a9c
;9@ r 9 _ a9c
;9c l * * 9c
;a9c l ] ] 9c
;8@ r * * 8@
;Cn r 8 @ 8@
;a8c l * * a8c
;8@ r 8 _ a8c
;8c l * * 8c
;a8c l ] ] 8c
;7@ r * * 7@
;Cn r 7 @ 7@
;a7c l * * a7c
;7@ r 7 _ a7c
;7c l * * 7c
;a7c l ] ] 7c
;6@ r * * 6@
;Cn r 6 @ 6@
;a6c l * * a6c
;6@ r 6 _ a6c
;6c l * * 6c
;a6c l ] ] 6c
;5@ r * * 5@
;Cn r 5 @ 5@
;a5c l * * a5c
;5@ r 5 _ a5c
;5c l * * 5c
;a5c l ] ] 5c
;4@ r * * 4@
;Cn r 4 @ 4@
;a4c l * * a4c
;4@ r 4 _ a4c
;4c l * * 4c
;a4c l ] ] 4c
;3@ r * * 3@
;Cn r 3 @ 3@
;a3c l * * a3c
;3@ r 3 _ a3c
;3c l * * 3c
;a3c l ] ] 3c
;2@ r * * 2@
;Cn r 2 @ 2@
;a2c l * * a2c
;2@ r 2 _ a2c
;2c l * * 2c
;a2c l ] ] 2c
;1@ r * * 1@
;Cn r 1 @ 1@
;a1c l * * a1c
;1@ r 1 _ a1c
;1c l * * 1c
;a1c l ] ] 1c
;0@ r * * 0@
;Cn r 0 @ 0@
;a0c l * * a0c
;0@ r 0 _ a0c
;0c l * * 0c
;a0c l ] ] 0c
;Z l @ Z 9
;z l @ z 9
;Y l @ Y 9
;y l @ y 9
;X l @ X 9
;x l @ x 9
;W l @ W 9
;w l @ w 9
;V l @ V 9
;v l @ v 9
;U l @ U 9
;u l @ u 9
;T l @ T 9
;t l @ t 9
;S l @ S 9
;s l @ s 9
;R l @ R 9
;r l @ r 9
;Q l @ Q 9
;q l @ q 9
;P l @ P 9
;p l @ p 9
;O l @ O 9
;o l @ o 9
;N l @ N 9
;n l @ n 9
;M l @ M 9
;m l @ m 9
;L l @ L 9
;l l @ l 9
;K l @ K 9
;k l @ k 9
;J l @ J 9
;j l @ j 9
;I l @ I 9
;i l @ i 9
;H l @ H 9
;h l @ h 9
;G l @ G 9
;g l @ g 9
;F l @ F 9
;f l @ f 9
;E l @ E 9
;e l @ e 9
;D l @ D 9
;d l @ d 9
;C l @ C 9
;c l @ c 9
;B l @ B 9
;b l @ b 9
;A l @ A 9
;a l @ a 9
;9c l @ 9 9
;8c l @ 8 9
;7c l @ 7 9
;6c l @ 6 9
;5c l @ 5 9
;4c l @ 4 9
;3c l @ 3 9
;2c l @ 2 9
;1c l @ 1 9
;0c l @ 0 9
;8 r * * 8
;9 r ( ( 8
;8 r ] _ 7
;7 l _ _ 6
;5 l * * 5
;0 * ( ( 5
;3 r * * 3
;5 l ) _ )3
;3 r * * 4
;)3 l _ _ 4
;4 r _ _ 3
;3 r ( _ 2
;2 l _ _ 1
;2 l * * 0
;6 l ( ( 0

Try it online!

Try it reversed!

I used this site to reverse it.

\$\endgroup\$
2
  • \$\begingroup\$ Well...! I hope you haven't written the first half, manually! I really hope! \$\endgroup\$
    – Night2
    Commented Sep 26, 2019 at 14:23
  • 1
    \$\begingroup\$ It really wasn't that much once I had the strategy sorted. After the basic logic was laid out, it was mostly copy/pasting/tweaking followed by debugging my muffed attempts at copy/pasting/tweaking. \$\endgroup\$
    – ouflak
    Commented Sep 26, 2019 at 15:33
5
\$\begingroup\$

05AB1E, 2 bytes

RI

Try it online or try it online reversed.

Explanation:

R   # Reverse the (implicit) input
 I  # Push the input
    # (output the top of the stack implicitly as result)

I   # Push the input
 R  # Reverse it
    # (output the top of the stack implicitly as result)
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Six more: ,R =R ?R Rs R¹ ¸R \$\endgroup\$
    – Makonede
    Commented Mar 30, 2021 at 16:32
  • \$\begingroup\$ qR works as well. \$\endgroup\$
    – Makonede
    Commented Apr 1, 2021 at 23:33
5
\$\begingroup\$

J, 7 bytes

,&.|:@]

Reversed:

]@:|.&,

Try it online!

Jonah's comment on Adam's APL answer made me take the challenge. It was pretty hard indeed, because the inflections . and : always attach to the symbol on their left, and a sole | (abstract value) isn't happy with strings.

How these work

Basically, it is a random mix of no-ops connected through various connectors.

,&.|:@]
     @]   Pass the argument unchanged
 &.|:     Apply inverse of |: (transpose), no-op on single string
,         Ravel, no-op on a single string
 &.|:     Apply |: again, still no-op

]@:|.&,
     &,   Ravel, no-op
 @:|.     Reverse
]         Pass the argument unchanged

This answer is one byte shorter than the trivial comment-abuse:

J, 8 bytes

]NB.BN.|

Reversed:

|.NB.BN]

Try it online!

In J, the in-line comment marker is NB., which is longer than every other language I know of.

\$\endgroup\$
4
\$\begingroup\$

Python 3, 27 bytes

lambda s:s#]1-::[s:s adbmal

Try it online!

!enilno ti yrT

\$\endgroup\$
4
\$\begingroup\$

Charcoal, 2 bytes

S←

Try it online! Explanation: implicitly prints the explicit input and moves the cursor left (no effect on the final output). Reversed:

←S

Try it online! changes the direction of the implicit print of the explicit input thus reversing the output.

\$\endgroup\$
0
4
\$\begingroup\$

Gaia, 2 bytes

pv

Try it online!

Try it reversed!

Very similar solution to other golfing languages.

Explanation

p    Print the (implicitly grabbed) input
 v   Reverse the input

Reverse

v    Reverse the (implicitly grabbed) input
 p   Print the result
\$\endgroup\$
1
  • \$\begingroup\$ Well that's certainly efficient. \$\endgroup\$
    – ouflak
    Commented Oct 24, 2019 at 18:47
4
\$\begingroup\$

J 9, 4 bytes

][.|

Attempt This Online!

See this answer for the 7-byter that works in previous versions.

J 9 (re-)introduces modifier trains and adds some adverb and conjunction equivalents of identity functions (] and [):

]: Ident (adverb)    / u]:  evaluates to u
]. Dex (conjunction) / u].v evaluates to v
[. Lev (conjunction) / u[.v evaluates to u

The above code parses as

] [. |    left operand ([.) out of identity(]) and absolute value(|),
          which is identity

while the reverse |.[] parses as a 3-train:

|. [ ]    left argument ([) out of the results of reverse (|.) and identity (])
          which is reverse
\$\endgroup\$
1
  • \$\begingroup\$ V nice, I had not noticed these new features \$\endgroup\$
    – Jonah
    Commented Sep 25, 2023 at 2:09
3
\$\begingroup\$

Cubix, 19 bytes

.@o?A^;/|?$oqBA.UW.

Try it online!

Cubified

    . @
    o ?
A ^ ; / | ? $ o
q B A . U W . .
    . .
    . .
  • A^ get all the input and enter the loop
  • o? output the TOS of stack and test
  • @ exit if it tests to negative
  • /;^ reflect back, pop TOS and re-enter loop

All other commands are avoided.

Reversed

.WU.ABqo$?|/;^A?o@.

Try it online!

Cubified

   . W
    U .
A B q o $ ? | /
; ^ A ? o @ . .
    . .
    . .
  • ABq Get all input, reverse and drop TOS to bottom of stack
  • o$?|? output TOS, skip the test and relect back onto test
  • @ halt if test if negative
  • WUq change lane, u-turn onto drop TOS start of loop
\$\endgroup\$
3
\$\begingroup\$

Pip, 4 bytes

aVRa

Try it online! !enilno ti yrT

Makes use of the fact that RV is the reverse operator but VR is an undefined variable. Both versions print the value of their last expression; in the standard version, that's a (with the first a and the VR being no-ops), while in the reversed version, that's RVa (with the first a being a no-op).

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

Perl 5 -p, 11 bytes

The obvious.

#esrever=_$
\$\endgroup\$
3
\$\begingroup\$

Pushy, 4 bytes

"\"@

Try it online: Forwards, Backwards

Simple implementation with the comment character \. In the forwards program, " prints the input and the rest is a comment; in the backwards program, @ reverses the input before printing.

We could alternatively replace \ with c, which would clear the input from the stack.

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

Wolfram Language (Mathematica), 16 10 bytes

esreveR@@D

Reversed:

D@@Reverse

Try it online! / Reversed

Input a list of characters. For string input, use StringReverse.

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

Jelly, 2 bytes

Uṛ

Try it online!

Reversed!

Explanation

U  | Reverse
 ṛ | Right argument (when used in a monadic chain like this, will return the original argument to the chain)

Explanation (reversed)

ṛ  | Right argument (when used in a monadic chain and followed by a monadic link, will return the output of that monadic link)
 U | Reverse

Seven other two-byters Ṛṛ ḷU ḷṚ Uȧ Ṛȧ ȯU ȯṚ

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

Japt, 2 bytes

ÔU

Try it | Reversed

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

MathGolf, 3 bytes

x;l

Explanation:

x   Reverse the implicit input
 ;  Discard the string
  l Push a string input
Implicit output TOS

Reversed:

l   Push a string input
 ;  Discard it
  x Reverse the implicit input
Implicit output TOS
\$\endgroup\$
2
\$\begingroup\$

C (gcc), 56 bytes

Nothing fancy. Would have used puts() but then trailing whitespace would not have been consistent between the two variants.

f(int*s){printf(s);}//};))1+s(f,s*(rahctup&&s*{)s*rahc(f

Try it online!

f(char*s){*s&&putchar(*s,f(s+1));}//};)s(ftnirp{)s*tni(f

Reversed!

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

W, 2 bytes

Pretty much the same as the 05AB1E solution.

a_

Explanation

a   % Push the input
 _  % Reverse the input
    % Implicit print the top of the stack

noitanalpxE

_   % Reverse the implicit input
 a  % Push the input
    % Implicit print the top of the stack
\$\endgroup\$
2
\$\begingroup\$

BRASCA (brasca-online), 5 bytes

The broken loops crash the Python-based interpreter, but it works on brasca-online.

,[o],
,]o[,

Try it! | !ti yrT

Explanation

,     - Reverses stack                     (1,2,3 => 3,2,1)
 [o]  - Output stack one by one            (3,2,1 => empty)
    , - Reverse it again                   (empty => empty)

Reversed:

,     - Reverses stack                     (1,2,3 => 3,2,1)
 ]o[  - Broken loops, output top of stack  (3,2,1 => 3,2  ) 
    , - Reverses it again                  (3,2   => 2,3  )
      - Implicit output the stack reversed (2,3   => empty)
\$\endgroup\$
2
+500
\$\begingroup\$

Factor, 17 bytes

[ ] ! ] esrever [

Try it online!

!enilno ti yrT

Fixed thanks to Bubbler

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think the reversed part should look like ] whatever [ :) \$\endgroup\$
    – Bubbler
    Commented Apr 1, 2021 at 23:19
  • \$\begingroup\$ @Bubbler Oops, you're right! I'll remind myself not to use a mirror next time :P \$\endgroup\$
    – user
    Commented Apr 1, 2021 at 23:20
2
\$\begingroup\$

Stack Exchange, 2 bytes

EP

Reversed:

PE

Sadly, there is no online interpreter, especially since this language is still a work in progress (although P and E are two of the commands I've finalized).

Stack Exchange is a language that resolves around stacks. It is a stack-based language where the only data structure is a stack. A string is represented as a stack of characters, and a character is represented by a stack of empty stacks where the length represents a codepoint.

The E command encloses all elements of the main stack in a stack and pushes that stack onto the main stack. The P dumps all elements of the top stack onto the main stack in reverse. P does this in reverse because it's easier to make it stack-safe that way, but I didn't realize until now that it's perfect for this challenge. Whereas PE dumps the input onto the stack in reverse and bundles it back up in a stack so it can be returned, EP encloses the input in a singleton stack and then unwraps it again, making no change.

As an example, running EP on the input { {{}{}{}} {} {{}{}} {{}} {} } returns the same stack back, whereas running PE returns { { {} {{}} {{}{}} {} {{}{}{}} } }. { {{}{}{}} {} {{}{}} {{}} {} } represents the string made of the characters \u0003, \u0000, \u0002, \u0001, and \u0000.

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

Brain-Flak, 13 bytes

#><}><)><}{({

Try it online!

Forward: Just a comment, so that it just outputs the input

Reversed:

{({}<>)<>}<>#

Try it online!

Move everything to the second stack, so it is reversed.

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

CJam, 7 bytes

qe#e%Wq

Boring version with comments. If CJam would fail silently i could have saved like 3 bytes in 2 questions already!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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