A Chiral Puzzle

45

5

A shape is chiral if no amount of rotation can make it look like it's mirror image. In this puzzle we will be writing chiral computer programs.

For this puzzle we will think of a program as a rectangular matrix of characters. As such all solutions to this challenge must be rectangular (that is all lines must be of the same length). We can rotate these programs in quarter turn increments. For example the program

The quickish fish
    lept deftly  
  rightwards     

When rotated a quarter turn clockwise looks like

  T
  h
r e
i  
glq
heu
tpi
wtc
a k
rdi
des
sfh
 t 
 lf
 yi
  s
  h

We can also reflect these programs. Here is the same program reflected over a vertical axis:

hsif hsikciuq ehT
  yltfed tpel    
    sdrawthgir   

A chiral program is a program that when rotated any number of times will always output "left". However when reflected produces a program that outputs "right" no matter how many times it is rotated.

Your task is to write a chiral program in as few bytes as possible.

Additional Rules

  • Output is not-case sensitive but should be consistent. (e.g. You may output "LEFT" and "rIgHt" but this casing must be consistent under rotations)

  • Lines are to be split either on a newline or a newline and a linefeed.

  • Your program must be a rectangle, you can pad it with spaces or comments but each line must have the same length.

  • You may optionally have a trailing newline (or newline and linefeed) on all of your programs if you wish.

Post Rock Garf Hunter

Posted 2018-09-11T16:19:46.423

Reputation: 55 382

Does anyone have a program that can autorotate its' input, cause that would at least make the process of creating all of this easier – KrystosTheOverlord – 2019-02-12T22:43:20.623

@KrystosTheOverlord I used this together with Vim's block commands and :set virtualedit=all mode. The initial Bool output checks if the input is equal to its own rotation, which simplifies things. Removing the {- makes it print the reflected input.

– Ørjan Johansen – 2019-02-13T00:44:24.080

@ØrjanJohansen Thank you, that really helps, up until now, I have been turning the screen of my laptop, thinking of what the outcome would be and trying to figure out how to rotate it!!! – KrystosTheOverlord – 2019-02-13T01:27:37.293

Answers

18

Pascal (FPC), 2161 755 349 bytes

///////bw(,,),(wb///////
///////er'''e''re///////
begin//girgtnflig//nigeb
write//itih'dteti//etirw
('le'//ne'' .''en//'ir'(
,'ft'//////////////'hg',
)end.////////////// 't',
,'t' //////////////.dne)
,'gh'//////////////'tf',
('ri'//ne''. ''en//'el'(
write//itetd'hiti//etirw
begin//gilfntgrig//nigeb
///////er''e'''re///////
///////bw(,),,(wb///////

Try left

Try right

@tsh motivated me to try again when I saw his program (in comment) and here it is!


Previous one with 755 bytes:

 begin write('left')end.// 
/e .dne)'thgir'(etirw nigeb
/g                        e
.i                       .g
dn                       di
n                        nn
ew                       e 
)r                       )w
'i                       'r
tt                       ti
fe                       ht
e(                       ge
l'                       i(
'r                       r'
(i                       'l
eg                       (e
th                       ef
it                       tt
r'                       i'
w)                       r)
 e                       we
nn                        n
id                       nd
g.                       i.
e                        g/
begin write('right')end. e/
 //.dne)'tfel'(etirw nigeb 

Try left

Try right

If you saw my previous submission, just forget it :)

All rotations for both left and right programs are the same.

AlexRacer

Posted 2018-09-11T16:19:46.423

Reputation: 979

1450 bytes – tsh – 2018-09-13T03:23:44.347

1I know those mirrored brackets are correct, but they still upset me. – Sellyme – 2018-09-13T05:54:05.613

1It looks like a framed mirror! – Frédéric Grosshans – 2018-09-14T07:36:25.623

@tsh Excellent idea! You motivated me to find better layout. – AlexRacer – 2018-09-16T18:48:48.417

299 bytes – Ørjan Johansen – 2018-09-17T04:57:47.707

11

Klein (000), 109 87 bytes

."left"@\.
\"right"..
@"thgir">.
..@"tfel"\
\"left"@..
.>"right"@
.."thgir"\
.\@"tfel".

Try it online!

Should be possible to get a shorter version of this answer so good luck!

This answer is inspired by spirals. In particular the idea is two interlocked spirals, one for left and one for right. It has two fold symmetry, So we can check the following programs to know it works:

Quarter turn

...\.@\.
\.>"."""
@""l@trl
"tre"hie
thiftggf
fggtfiht
eih"ert"
lrt@l""@
""".">.\
.\@.\...

Try it online!

Mirrored

.\@.\...
""".">.\
lrt@l""@
eih"ert"
fggtfiht
thiftggf
"tre"hie
@""l@trl
\.>"."""
...\.@\.

Try it online!

Mirrored and Quarter turn

.\@"tfel".
.."thgir"\
.>"right"@
\"left"@..
..@"tfel"\
@"thgir">.
\"right"..
."left"@\.

Try it online!

Post Rock Garf Hunter

Posted 2018-09-11T16:19:46.423

Reputation: 55 382

10

Klein (000), 27 25 bytes

\(("right"@/
\(("left"@!\

Try it online! Rotated once! Rotated twice! Rotated three times!

And flipped: Try it online! Rotated once! Rotated twice! Rotated thrice!

The only one that gave me a bit of trouble was the flipped and rotated once, which looks like:

\/
!@
@"
"t
th
fg
ei
lr
""
((
((
\\

This is the only reason for the two sets of ((.

Jo King

Posted 2018-09-11T16:19:46.423

Reputation: 38 234

9

Klein (211), 37 bytes

!\"left"@"thgir"\!
!/............../!

This has a different program for each rotation.

Explanation

Note that each of these programs is padded to a square with no-ops before execution

No change

!\"left"@"thgir"\!
!/............../!

Try it online!

! makes execution jump over the \ and "left"@ loads the string "left" into the stack and terminates the program printing the stack

Quarter turn

!!...IP->
\/
".
r.
i.
g.
h.
t.
".
@.
".
t.
f.
e.
l.
".
\/
!!
^
|
P
I

Try it online!

Execution runs off the top right corner of the square, continues in the bottom left corner and once again !\"left"@ prints "left.

Half turn

                ^
                |
                P
                I
!/............../!
!\"right"@"tfel"\!
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
................^.
................|.
IP->............P.
................I.

Try it online!

Here, the execution path exits from the North side, re-enters through the West side, exits again from the East Before entering in the south. \ bounces the path into "left"@ to print it.

Three-quarter turn

!!..IP->
/\
."
.l
.e
.f
.t
."
.@
."
.t
.h
.g
.i
.r
."
/\
!!
^
|
I
P

Try it online

Execution exits from the top right corner then re-enters in the bottom left. Once again the mirrors /\ redirect the path into "left"@ to print it.

Reflection

!\"right"@"tfel"\!
!/............../!

This is essentialy the same as for left in all rotations.

jslip

Posted 2018-09-11T16:19:46.423

Reputation: 721

9

JavaScript (Node.js), 1481 599 505 461 341 305 271 bytes

/g+///g/g"c.c"g/
g=//////=rolol=g
"left"///inone/+
console//gsgsf//
.log(g)//ho(ot//
console//tlgl"//
"right"//"e)e//g
g=//////////////
//////////////=g
g//e)e"//"thgir"
//"lglt//elosnoc
//to(oh//)g(gol.
//fsgsg//elosnoc
+/enoni///"tfel"
g=lolor=//////=g
/g"c.c"g/g///+g/

Mirrored

/g"c.c"g/g///+g/
g=lolor=//////=g
+/enoni///"tfel"
//fsgsg//elosnoc
//to(oh//)g(gol.
//"lglt//elosnoc
g//e)e"//"thgir"
//////////////=g
g=//////////////
"right"//"e)e//g
console//tlgl"//
.log(g)//ho(ot//
console//gsgsf//
"left"///inone/+
g=//////=rolol=g
/g+///g/g"c.c"g/

Try it online!

(Please see the TIO Link for all test cases, including mirrored version)

Although further golfed, size 22x22 -> 21x21 on credit of @JoKing!

Size 38x38 24x24 22x22 21x21 18x18 17x17 16x16, 4-fold symmetry.

Here comes a question -- is it possible to have 15x15 or smaller for JS? It seems that what I need at least is the comment separator between two sub-blocks and at the edge, so at least 7+2+2+5=16 lines?

Shieru Asakoto

Posted 2018-09-11T16:19:46.423

Reputation: 4 445

@JoKing Oh that seems practicable. I'd have a try ;) – Shieru Asakoto – 2018-09-12T09:41:11.077

@JoKing Got down to 21x21, thanks ;) – Shieru Asakoto – 2018-09-12T10:11:34.377

8

Canvas, 109 89 71 bytes

(tfel⁸((
(h(right
⁸g   q(f
li    re
er    il
f(    g⁸
thgir(h(
((⁸left(

Try it here | Try reversed! Those are the only two possible programs, as the program is rotationally symmetric.

Made in this.

dzaima

Posted 2018-09-11T16:19:46.423

Reputation: 19 048

4What an empty canvas over there... :/ – Erik the Outgolfer – 2018-09-11T17:02:19.530

8

Gol><>, 23 bytes

\"thgir"H /
\"tfel"H.9\

Try it online!

This is the same format as my Klein answer, but 2 bytes shorter. Maybe there's another 2D language out there that can golf those last 2 bytes off... But for now, this is as short as it gets.

Jo King

Posted 2018-09-11T16:19:46.423

Reputation: 38 234

oof, I just spent the past hour making this in gol><>, then I scroll down to find this. Good job though! – KrystosTheOverlord – 2019-02-13T03:55:03.163

7

Alice, 25 bytes

}/"regttoo {
{/"lifh""@@{

Left: Normal, 1/4 turn clockwise, 1/2 turn, 1/4 turn counterclockwise

Right: reflect across horizontal axis, down-right diagonal, vertical axis, up-right diagonal

Explanation

This program has three parts. The first part is the three {s and one } on the corners. The { turn the IP left until it reaches the }, at which point it turns right. In the reflected version, the IP goes along the top row in the original program. In the original version, turning right will immediately hit the adjacent {, pointing the IP along the bottom row in the original program.

Next are the two slashes in the second column. If the program is horizontally oriented, either type of slash would simply change to ordinal mode, sending the IP in the same left/right direction it was already going. If the program is vertically oriented, the IP bounces around quite a bit more, but making them both forward slashes gives the same end result. (Two backslashes would give the opposite result, and one of each would create an infinite loop.)

The rest of the program is straightforward. The IP in ordinal mode bounces diagonally, so either "left"o@ or "right"o@ will be run depending on how this section was entered.

Nitrodon

Posted 2018-09-11T16:19:46.423

Reputation: 9 181

7

Hexagony, 98 bytes

\.@.t;./r.
.)@.;...;.
ll..)gt.;$
;.i<;;;i);
e;@.)@e;.l
.;e;d.g|.|
rt/;t.;)g\
@f.#l.;..r
\.;\.;i\.i

Try it online! | Rotated 90° | Rotated 180° | Rotated 270°
Reversed | Rotated 90° & Reversed | Rotated 180° & Reversed | Rotated 270° & Reversed

Hexagony was kind of fun for this challenge, because a rotation or a reversal can drastically change the actual program. Each Rotation/Reversal is its own unique program. Some of the program execution paths are much more interesting than others.

I will admit that coming up with this took longer than it probably should have. I am pretty sure a shorter answer can be done in Hexagony, so good luck!

Jo.

Posted 2018-09-11T16:19:46.423

Reputation: 974

6

Haskell, 461 379 bytes

82 bytes saved by Ørjan Johansen

--_----------mppr--
-- ----------a  l--
rl=p  p--   niam= _
p m="left"-- n==p--
p a="right"++ "" --
main  =putStr rl --
--n +r       =iep--
-- -+t       pgf---
-- -"S       uht---
-- "tt       tt" --
---thu       S"- --
---fgp       t+- --
--pei=       r+ n--
-- lr rtStup=  niam
-- "" ++"thgir"=a p
--p==n --"tfel"=m p
_ =main   --p  p=lr
--l  a---------- --
--rppm----------_--

Try it online!

Since this one has 4-fold symmetry you only need to test the mirror:

--rppm----------_--
--l  a---------- --
_ =main   --p  p=lr
--p==n --"tfel"=m p
-- "" ++"thgir"=a p
-- lr rtStup=  niam
--pei=       r+ n--
---fgp       t+- --
---thu       S"- --
-- "tt       tt" --
-- -"S       uht---
-- -+t       pgf---
--n +r       =iep--
main  =putStr rl --
p a="right"++ "" --
p m="left"-- n==p--
rl=p  p--   niam= _
-- ----------a  l--
--_----------mppr--

Try it online!

This is a start. It is far from ideal, but there are a few interesting things going on here. Haskell is a certainly an interesting language for this challenge. I look forward to an answer that beats this be it mine or someone else's.

Post Rock Garf Hunter

Posted 2018-09-11T16:19:46.423

Reputation: 55 382

1

Shortened this to 379 bytes (19x19)

– Ørjan Johansen – 2018-09-12T06:44:44.170

6

Ruby, 131 bytes

#######:$:#
:right#l>r#
$><<###e<i#
:left##f<g#
####   t#h#
#t##   ##t#
#h#t   ####
#g<f##tfel:
#i<e###<<>$
#r>l#thgir:
#:$:#######

Try it online!

Kirill L.

Posted 2018-09-11T16:19:46.423

Reputation: 6 693

6

APL (dzaima/APL), 181 bytes

The program has rotational symmetry so only two cases need to be checked


Left

⍝⍝⍝⍝⍝⍝⍝  t⎕t⍝
t←'lef'⍝ ←←←⍝
⎕←t,     't'⍝
t←'righ'⍝r,l⍝
   ⍝     i e⍝
 ⍝ '     g f⍝
⍝' h     h '⍝
⍝f g     t ⍝ 
⍝e i     ⍝   
⍝l,r⍝'hgir'←t
⍝'t'     ,t←⎕
⍝←←← ⍝'fel'←t
⍝t⎕t  ⍝⍝⍝⍝⍝⍝⍝

Try it online!

Right

⍝t⎕t  ⍝⍝⍝⍝⍝⍝⍝
⍝←←← ⍝'fel'←t
⍝'t'     ,t←⎕
⍝l,r⍝'hgir'←t
⍝e i     ⍝   
⍝f g     t ⍝ 
⍝' h     h '⍝
 ⍝ '     g f⍝
   ⍝     i e⍝
t←'righ'⍝r,l⍝
⎕←t,     't'⍝
t←'lef'⍝ ←←←⍝
⍝⍝⍝⍝⍝⍝⍝  t⎕t⍝

Try it online!

Explanation

This is my first APL program so it is pretty simple. It only uses one trick that I think is interesting.

If we start by stripping away all the comments we get the following programs

Left

t←'lef'
⎕←t,     't'
t←'righ'

Right

t←'righ'
⎕←t,     't'
t←'lef'

Starting from the left program we do three things.

  1. Assign 'lef' to the variable t

  2. Print the variable t and the letter 't'

  3. Assign 'righ' to the variable t

Now because it is the mirror the right program does these three steps but in the opposite order. This means that we print 'left' for the left program and 'right' for the right program.

The one trick here is that the 't' actually comes from a rotated copy of the code. If you look at the third colum of our code you will see that it is 't'. We reuse this 't' in the rotated versions to append the t that is needed.

Post Rock Garf Hunter

Posted 2018-09-11T16:19:46.423

Reputation: 55 382

4

Prolog (SWI), 649 188 bytes

Unflipped, Unrotated

:-%    l :%r     %-:
write(%e%-(i %(etirw
left).%f.weg%.)right
%      t)rth.      %
%      )tiit)      %
%      .htr)t      %
right).%gew.f%.)left
write(% i(-%e%(etirw
:-%     r%: l    %-:

Try it online!

Unflipped, Rotated

:wr%%%lw:
-ri   er-
%ig   fi%
 th   tt 
 et   )e 
 ()   .( 
 %.   %% 
  %.)tfel
right).% 
%(etirw-:
:-write(%
 %.)thgir
left).%  
 %%   .% 
 (.   )( 
 e)   re 
 tl   it 
%ie   gi%
-rf   hr-
:wt%%%tw:

Try it online!

Flipped, Unrotated

:-%     r%: l    %-:
write(% i(-%e%(etirw
right).%gew.f%.)left
%      .htr)t      %
%      )tiit)      %
%      t)rth.      %
left).%f.weg%.)right
write(%e%-(i %(etirw
:-%    l :%r     %-:

Try it online!

Flipped, Rotated

:wl%%%rw:
-re   ir-
%if   gi%
 tt   ht 
 e)   te 
 (.   )( 
 %%   .% 
left).%  
 %.)thgir
:-write(%
%(etirw-:
right).% 
  %.)tfel
 %.   %% 
 ()   .( 
 er   )e 
 ti   lt 
%ig   ei%
-rh   fr-
:wt%%%tw:

Try it online!

0 '

Posted 2018-09-11T16:19:46.423

Reputation: 3 439

4

Prolog (SWI), 239 223 209 181 bytes

%%%%%%%  l:r%
right).% e-i%
:-write(%fwg%
left).%  trh%
  %      )it%
 %(      .t)%
%.e%     %e.%
%)t.      (%
%ti)      %
%hrt  %.)tfel
%gwf%(etirw-:
%i-e %.)thgir
%r:l  %%%%%%%

Try it online!

Since the program has 4 fold symmetry you only need to check the mirror:

%r:l  %%%%%%%
%i-e %.)thgir
%gwf%(etirw-:
%hrt  %.)tfel
%ti)      %  
%)t.      (% 
%.e%     %e.%
 %(      .t)%
  %      )it%
left).%  trh%
:-write(%fwg%
right).% e-i%
%%%%%%%  l:r%

Try it online!

Post Rock Garf Hunter

Posted 2018-09-11T16:19:46.423

Reputation: 55 382

4

Python 2, 209 bytes (14 x 14)

Normal (left):

##########sps#
s="left"##=r=#
print s###"i"#
s="right"#rnl#
####      ite#
###"      g f#
#"#t      hst#
#tsh      t#"#
#f g      "###
#eti      ####
#lnr#"thgir"=s
#"i"###s tnirp
#=r=##"tfel"=s
#sps##########

Try it online!

Reflected (right):

#sps##########
#=r=##"tfel"=s
#"i"###s tnirp
#lnr#"thgir"=s
#eti      ####
#f g      "###
#tsh      t#"#
#"#t      hst#
###"      g f#
####      ite#
s="right"#rnl#
print s###"i"#
s="left"##=r=#
##########sps#

Try it online!

Curtis Bechtel

Posted 2018-09-11T16:19:46.423

Reputation: 601

3

05AB1E (legacy), 89 55 bytes

'…¸q©ƒ'
ƒ     …
©     ¸
q     q
¸     ©
…     ƒ
'ƒ©q¸…'

Very basic approach. Outputs in full lowercase.

Try it online or try it online reflected (each rotation is the same).

Explanation:

'…¸   '# Push the dictionary string "left" to the stack
   q   # Stop the program (and output the top of the stack implicitly)
       # Everything else after it is ignored

Reversed:

'ĩ   '# Push the dictionary string "right" to the stack
   q   # Stop the program (and output the top of the stack implicitly)
       # Everything else after it is ignored

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why '…¸ is "left" and 'ƒ© is "right".

Kevin Cruijssen

Posted 2018-09-11T16:19:46.423

Reputation: 67 575

Are the ignored commands really no-ops, or just never reached because of the q? – Ørjan Johansen – 2019-02-13T18:25:37.360

@ØrjanJohansen Second indeed, they are never reached. So technically not really no-ops (which is the term I usually use for all code that's ignored in my answers). This also doesn't work in the new version of 05AB1E, because it seems to look at the code first (sort of compile), and only then executes. Whereas the Legacy version just starts executing I think. Which is why I specified I've used the (legacy) version of 05AB1E. – Kevin Cruijssen – 2019-02-13T21:54:23.993

3

Clean, 1331 1055 bytes

-276 bytes thanks to Ørjan Johansen

// ////////////;/;/////////// //
// ////////////S/S/////////// //
  module m////mtmt////m eludom  
//o///////////=a=a///////////o//
//d///////////"r"r///////////d//
//u///////////tttt///////////u//
//l///////////f#h#///////////l//
//e///////////emgm///////////e//
// ///////////loio/////////// //
//m///////////"drd///////////m//
//////////////=u"u//////////////
//////////////ml=l//////////////
//////////////#eme//////////////
////////////// =#=//////////////
;Start#module= 0   #m="left"=m//
//m="thgir"=m#   0=eludom#tratS;
;Start#module=0   #m="right"=m//
//m="tfel"=m#   0 =eludom#tratS;
//////////////=#= //////////////
//////////////eme#//////////////
//////////////l=lm//////////////
//////////////u"u=//////////////
//m///////////drd"///////////m//
// ///////////oiol/////////// //
//e///////////mgme///////////e//
//l///////////#h#f///////////l//
//u///////////tttt///////////u//
//d///////////r"r"///////////d//
//o///////////a=a=///////////o//
  module m////tmtm////m eludom  
// ///////////S/S//////////// //
// ///////////;/;//////////// //

Try "left" online!

Try "right" online!

This was difficult for many reasons:

  • Clean requires a file header module <filename> be present at the start, and only the start of the file. Unfortunately, this means that for the rotations of the mirrored program to be valid it also has to appear at the bottom of the file. To make this worse, module .. is invalid for global, let .. in, where .. and with .. definitions; and the token module appearing if it hasn't been defined causes an error.
  • Both block comments and line comments nest: /* /* */ leaves one level of comment open, and so does /* // */ (as well as commenting the rest of the line out).
  • The same function can be defined multiple times, but only directly after itself.

Fortunately, we can define module as something in a #.. (let-before) expression, which is all we need. Because Clean doesn't type-check alternatives that are never used (and a variety of other equally unused things), the requisite second definition of Start can be complete garbage. This allows us to use the second Start to consume the module header at the bottom of the file because Clean treats m module m as calling the function m on module and m (which since we've defined module and m, doesn't cause an error). It doesn't matter that m is a string and not a function, because the Start alternative never gets type-checked.

This is easier to see if you look at it through the compiler's eyes:

module m;
Start#module=0#m="left"=m;
Start#module=0#m="right"=m module m

Οurous

Posted 2018-09-11T16:19:46.423

Reputation: 7 916

11055 merging m and s. – Ørjan Johansen – 2019-02-14T04:52:33.483

@ØrjanJohansen Oooh nice catch! – Οurous – 2019-02-14T04:57:08.107

3

Brachylog, 341 bytes

Ẹw"thgir"∧"left"wẸ
w"              "w
"                "
t                t
f                h
e                g
l                i
"                r
∧                "
"                ∧
r                "
i                l
g                e
h                f
t                t
"                "
w"              "w
Ẹw"tfel"∧"right"wẸ

Try it online!

!enilno ti yrT

Takes advantage of Brachylog taking the main predicate to be the one on the first line and not much caring about the other lines beyond requiring that they can compile. Unreflected, it prints an empty string followed by "left" on the same line, and reflected it prints an empty string followed by "right" on the same line. I'm tempted to think there might be a way to make a (usefully) non-square version using , but that might be plenty tricky without trying to make it work differently under reflection.

Unrelated String

Posted 2018-09-11T16:19:46.423

Reputation: 5 300

2

Batch, 438 321 bytes

:::::::::::::@@@:
@echo left&: eee:
@exit/b&:    cxc:
@echo right&:hih:
:  :         oto:
:: &          / :
:& t         rbl:
:t h         i&e:
:f:g         g:f:
:e&i         h t:
:lbr         t &:
: /          & ::
:oto         :  :
:hih:&thgir ohce@
:cxc    :&b/tixe@
:eee :&tfel ohce@
:@@@:::::::::::::

Explanation: A : is used to indicate a label, which is as good as a comment, so as the program has rotational symmetry the only difference between the two versions is which of the @ lines is first, in which case either left or right is output before the script exits.

I did try creatively overlapping the rotated lines with each other but my attempt actually ended up with a larger grid.

Edit: Saved 117 bytes thanks to @ØrjanJohansen.

Neil

Posted 2018-09-11T16:19:46.423

Reputation: 95 035

I think you can replace &rem by &:. – Ørjan Johansen – 2018-09-13T01:31:15.407

@ØrjanJohansen I seem to remember trying that before on a similar challenge, but I don't think it worked well. – Neil – 2018-09-13T10:50:53.440

This (don't mind the Haskell, TIO doesn't seem to have Batch) worked for me as test.bat in the Win10 command prompt. – Ørjan Johansen – 2018-09-14T00:51:05.273

@ØrjanJohansen Fair enough, it might have been a bug in a previous version of CMD.EXE or something. – Neil – 2018-09-14T08:45:17.807

2

Ruby, 181 bytes

#########tpt#
t=:left##=u=#
puts t###:t:#
t=:right#rsl#
####     i e#
###t     gtf#
#t#h     h#t#
#ftg     t###
#e i     ####
#lsr#thgir:=t
#:t:###t stup
#=u=##tfel:=t
#tpt#########

Try it online!

This is a port of Curtis Bechtel's Python answer to Ruby, golfed a little more.

Actually, his Python program is a polyglot and runs on Ruby too, so my first answer was a copy-paste of it, but it seemed unfair. So I wrote a script that generates a new answer starting from a base script. You can try it here:

Build your own

G B

Posted 2018-09-11T16:19:46.423

Reputation: 11 099

2

Stax, 131 bytes

 .Cq"tfel" 
""`KT?`qC".
lC       `C
eq       Kq
f`       T"
t?       ?t
"T       `f
qK       qe
C`       Cl
."Cq`?TK`""
 "left"qC. 

Run and debug it

This is the "right" variant.

recursive

Posted 2018-09-11T16:19:46.423

Reputation: 8 616

1

Runic Enchantments, 116 bytes

> \ !U\L
 ...@.. 
 \.R""" 
 @""trl 
 "lrhie 
 teiggf 
 ffgiht 
 ethrt" 
 l"t""@ 
 " "R.\ 
 .\@.@. 
DR\!!/R 
     !! 

Try it online!

And reversed

Not exactly a port, but utilized Post Left Garf Hunter's Klein 000 answer as a starting point, given the typical near-compatibility of the two languages (most commands are the same and the edge wrapping in Runic is identical to Klein 000). The only issue was that Klein IPs always start from the top left and Runic's do not. As such the . are all part of the original code and still treated as NOP by Runic, while the are NOPs I had to add as part of controlling the flow.

Prints "left" in all 4 rotations and "right" when mirrored (and in all four rotations thereof). Two middle columns were completely unused after my modifications, so I was able to remove them.

In theory a rotation with lots of trailing whitespace could be used for a lower byte count (eg. this variant), however the spaces are needed to correctly rotate the structure using external tools and so I included them.

Below variants contain the unused chunks that were removed, but are otherwise identical:

All four lefts. Outputs leftleftleftleft (the fact that all four can be run like this is coincidence).

Right 1, Right 2, Right 3, Right 4

Draco18s no longer trusts SE

Posted 2018-09-11T16:19:46.423

Reputation: 3 053

1

Gol><>, 342 bytes

 8A_          _A8 
9       ""       9
A       LR       A
_       EI       _
        FG        
        TH        
        "T        
         "        
 "TFEL" HH"RIGHT" 
 "THGIR"HH "LEFT" 
        "         
        T"        
        HT        
        GF        
_       IE       _
A       RL       A
9       ""       9
 8A_          _A8  

Wow! That took longer than I expected, halfway through I realized the reflection was vertically, not horizontally like I had been coding for! I'm pretty sure that this works, but if I made a mistake please let me know. This can most likely be golfed a ridiculous amount more, I just took an extreme brute force method to do so. The shape itself is actually a square, it is technically symmetric, except on across the x-axis, so when it flips, it returns "RIGHT" instead!!!

The character that made this program possible is the 'A', which allows for teleportation to the beginning of a certain line!

Try it online!

KrystosTheOverlord

Posted 2018-09-11T16:19:46.423

Reputation: 681

1Vertical and horizontal reflection shouldn't make a difference since they are the same after a rotation. – Post Rock Garf Hunter – 2019-02-13T03:53:47.060

@TRITICIMAGVS Huh, didn't think of that, thanks for pointing that out, also I just realized this entire thing is pointless, JoKing made one that was 27 bytes in size – KrystosTheOverlord – 2019-02-13T03:56:21.523

1Eh, I think it is always worth it if you enjoyed the process. – Post Rock Garf Hunter – 2019-02-13T03:58:10.283