Let's play tennis 2: east-west game

There is a challenge Let's play tennis by Daniel. He proposes to place a court in the North-South direction. My proposal is to create a court to play tennis in the East-West direction too.

You have to print a tennis court, but you have to do it in the fewest bytes possible because of confidential reasons.

Tennis court

------x------
|  |  x  |  |
|  |--x--|  |
|  |  x  |  |
------x------


Original rules are:

• No extra spaces.
• No tabs as they would be unfair.
• One optional trailing newline is allowed.

Canvas, 13 12 bytes

«ω↕9:gＷ：ｔＣ‟┼


quad-palindromizes a compressed corner of the field.

Try it here!

11 bytes with uppercase Xes, using the fact that / compresses better than x and palindromizing would result in overlapping / and its mirror \, which results in X

• See, my thinking when I first saw this question was "do I have enough time to go learn Canvas right now and then post a solution?" Evidently not :P – Quintec Oct 21 '18 at 20:33

Python 2, 59 bytes

s="------x------\n|  |  x  |  |\n|  |--x"
print s+s[-2::-1]


Try it online!

Prints the first half of the string followed by its reverse. It's boring but efficient. I tried extracting repeating parts of out s, especially the -, but didn't find anything shorter.

Python 2, 59 bytes

for n in 6,0,2,0,6:x='-'*n+'  |  |'[n:];print x[::-1]+'x'+x


Try it online!

Using Jo King's construction.

Python 2, 62 bytes

b='|  '*2
for r in'-'*6,b,'|  |--',b,'-'*6:print r+'x'+r[::-1]


Try it online!

Prints the first half of each line, followed by 'x', followed by the first half reversed.

Charcoal, 15 bytes

↑²←⁶↓xx→x²↑²‖Ｏ¬


Try it online! Link is to verbose version of code. By way of explanation I will show the result after each of the drawing commands up to the final reflection:

↑²        |
|

------
←⁶        |
|

x------
↓xx x     |
|

x------
→x² x     |
x--   |

x------
↑²  x  |  |
x--|  |


Python 3, 65 62 bytes

for n in 7,0,3,0,7:x="-"*n+"|  "*5;print(x[6:0:-1]+'x'+x[1:7])


Try it online!

• Now this is the kind of string-slicing wizardry that I thought a Python answer to this challenge ought to have. Well played! – DLosc Oct 22 '18 at 1:45

Dyalog APL, 36 bytes

(⌽,'x',⊢)(⊢⍪'--|  |'⍪⊖)'-'⍪1 6⍴'  |'


Try it online!

With a little help from Adám

Python 3, 75 bytes

s='-'*6;p='|  |';w=s+'x'+s;a=p+'  x  '+p;print(w,a,p+w[4:9]+p,a,w,sep='\n')


Probably golfable - I've never really tried challenges before.

Try it online!

In Python 2 I could get it to 76 bytes

s='-'*6;p='|  |';w=s+'x'+s;a=p+'  x  '+p
for i in w,a,p+w[4:9]+p,a,w:print i


say$_,x,~~reverse for('-'x6,'| 'x2,'| |--')[0..2,1,0]  Try it online! APL (Dyalog Classic), 35 bytes ' |-x'[(⍉⊖⍪1∘↓)⍣2⍉3⍪2,⍨676 28⊤⍨6⍴3]  Try it online! • I just saw this now holy what – Quintec Oct 31 '18 at 13:52 Pip-l, 4239 34 bytes RV@<P"| |".[s'-]X2PE'-X6M_.'x.RV_  Try it online! Alternate solution, also 34 bytes: RV@<P"-0| 0| |--"^0M_@<16RA6,t'x  Try it online! Python 2, 6968 66 bytes -2 thanks to Jo King for l in"-","| ","| |--","| ","-":l*=6;print l[:6]+"x"+l[5::-1]  Try it online! We cycle the following three patterns infinitely (6 times is sufficiently infinite for our purposes) and slice off the first 6 characters of each: -, | , and | |--. Then, to get the tennis court, we concatenate an x and the reverse of each line. J, 53 bytes echo|:'x'(<6)}'-'(<2;~4+i.5)}13$3 5$'-|||',11$'--   '


Try it online!

MBASIC, 82 bytes

1 WIDTH 13:PRINT"------x------|  |  x  |  ||  |--x--|  ||  |  x  |  |------x------


Abusing the WIDTH directive saved me around 20 bytes.

Stax, 19 bytes

⌡x♠=Γτ^┼¢Δ¶─êiö\$≥⌐▓


Run and debug it

K (ngn/k), 34 bytes

+"x-| "@4\509 425 477 0@4\17218113


Try it online!

Port of K4 answer. 2 bytes saved with the 4\, 1 byte lost due to the +

05AB1E, 25 24 bytes

"
-x|"•L®y[Â-Γ•5вèJ.º.∊


Try it online.

25 24 bytes alternative:

… -|•B°”Ñ•3вèJ3ä'x«».º.∊


Try it online.

Explanation:

"\n -x|"       # Push string "\n -x|"
•L®y[Â-Γ•      # Push compressed number 5960566858660563
5в    # Converted to Base-5 as list:
#  [2,2,2,2,2,2,3,0,4,1,1,4,1,1,3,0,4,1,1,4,2,2,3]
è              # Index each digit into the string
J             # And join the list together
#  "\n -x|" and [2,2,2,2,2,2,3,0,4,1,1,4,1,1,3,0,4,1,1,4,2,2,3]
#   → "------x\n|  |  x\n|  |--x"
.º             # Intersect mirror everything horizontally
.∊           # Intersect mirror everything vertically (and output implicitly)

… -|           # Push string " -|"
•B°”Ñ•         # Push compressed integer 193812448
3в       # Converted to Base-3 as list: [1,1,1,1,1,1,2,0,0,2,0,0,2,0,0,2,1,1]
è              # Index each digit into the string
J             # And join the list together
#  " -|" and [1,1,1,1,1,1,2,0,0,2,0,0,2,0,0,2,1,1]
#   → "------|  |  |  |--"
3ä             # Split the string into three parts: ["------","|  |  ","|  |--"]
'x«         '# Append an "x" to each: ["------x","|  |  x","|  |--x"]
»         # Join by newlines: "------x\n|  |  x\n|  |--x"
.º             # Intersect mirror everything horizontally
.∊           # Intersect mirror everything vertically (and output implicitly)


See this 05AB1E tip of mine (section How to compress large integers?) to understand why •L®y[Â-Γ• is 5960566858660563 and •B°”Ñ• is 193812448.

Thanks to @MagicOctopusUrn's ASCII-art generator for •L®y[Â-Γ•5BžLR"\n -x|"‡ and •B°”Ñ•3BžLR" -|"‡, after which the transliterate has been golfed further by swapping the number and string on the stack, use в instead of B, and index into the string with è.

Bubblegum, 28 bytes

00000000: d3d5 0581 0a30 a9cb 55a3 a000 4415 60b2  .....0..U...D..
00000010: 06cc 03cb c179 0839 5d14 7d00            .....y.9].}.


Try it online!

Jelly, 22 bytes

“Þḅ“ H“ \’ṃ“-|x ”ŒBŒḄY


Try it online!

V, 25 bytes

13é-Äï5I  |<esc>ÄÙ4l5r-Îd^ãrx


Try it online!

Hexdump:

00000000: 3133 e92d c4ef 3549 2020 7c1b c4d9 346c  13.-..5I  |...4l
00000010: 3572 2dce 645e e372 78                   5r-.d^.rx


Here was my process:

13é-Äï5I  |<esc>3<<ÄÙ4l5r-Gã<C-v>ërx
13é-Äï5I  |<esc>3<<ÄÙ4l5r-Î7|rx
13é-Äï5I  |<esc>3<<ÄÙ4l5r-Îãrx
13é-Äï5I  |<esc>ÄÙ4l5r-Îd^ãrx


Alternate version:

5I  |<esc>5ÄM4l5r-HÒ-G.Îxxãrx


Hexdump:

00000000: 3549 2020 7c1b 35c4 4d34 6c35 722d 48d2  5I  |.5.M4l5r-H.
00000010: 2d47 2ece 7878 e372 780a                 -G..xx.rx.


JavaScript (Node.js), 76 bytes

(a='----',A='|  |',b='--x--',B='  x  ')=>[p=a+b+a,q=A+B+A,A+b+A,q,p].join



Try it online!

• 68 bytes if array of strings allowed.

JavaScript (Node.js), 75 bytes

_=>[p='x---',q='x|  ','x| -',q,p].map(c=>[...'1221330331221'].map(d=>c[d]))


Try it online!

• This one output 2d char array. I don't know if it can be golfed further more.

Red,98 80 bytes

foreach r[1 2 3 2 1][print pick["------x------""|  |  x  |  |""|  |--x--|  |"]r]


Try it online!

Pyth, 32 bytes

t_ps@L"x-
| "jC"??ôkË7"5


Try it online here. The above code contains some odd characters, so copying/pasting probably won't work.

Prints the first half of the pattern, followed by its reverse without the central x.

t_ps@L"x-\n| "jC"..."5   Note newline replaced with \n, encoded string replaced with ...

C"..."    Convert encoded string to base 256 number 727558509253668163499780
j      5   Convert to base 5, yields [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 2, 3, 4, 4, 3, 4, 4, 0, 4, 4, 3, 4, 4, 3, 2, 3, 4, 4, 3, 1, 1, 0]
@L                   Map each of the above to...
"x-\n| "           ... [x, -, newline, |, space]
s                     Concatenate into string
p                      Print without newline
_                       Reverse
t                        All but first character, implicit print


Powershell, 60 59 bytes

('------x------','|  |  x  |  |','|  |--x--|  |')[0,1+2..0]

• 59 bytes to do [0,1+2..0] – AdmBorkBork Oct 22 '18 at 14:59

C# (.NET Core), 88 bytes

string a="------x------\n",b="|  |  x  |  |\n";Console.Write(a+b+"|  |--x--|  |\n"+b+a);


Try it online!

Ungolfed:

string a = "------x------\n",
b = "|  |  x  |  |\n";
Console.Write(a + b + "|  |--x--|  |\n" + b + a);


Here's an alternate way to do it with an anonymous function based on adrianmp's answer from the first Let's Play Tennis thread:

C# (.NET Core), 88 bytes

()=>{string a="------x------\n",b="|  |  x  |  |\n";return(a+b+"|  |--x--|  |\n"+b+a);};


Try it online!

Ungolfed:

() =>
{
string a = "------x------\n",
b = "|  |  x  |  |\n";
return(a + b + "|  |--x--|  |\n" + b + a);
};


K4, 36 35 bytes

Solution:

"x-| "@4\:509 425 477 0@4\:17218113


Example:

q)k)"x-| "@4\:509 425 477 0@4\:17218113
"------x------"
"|  |  x  |  |"
"|  |--x--|  |"
"|  |  x  |  |"
"------x------"


Explanation:

We want to generate a list of indexes into the array "x-| ", e.g.

1 1 1 1 1 1 0 1 1 1 1 1 1
2 3 3 2 3 3 0 3 3 2 3 3 2
2 3 3 2 1 1 0 1 1 2 3 3 2
2 3 3 2 3 3 0 3 3 2 3 3 2
1 1 1 1 1 1 0 1 1 1 1 1 1


In order to generate this we can take the base-4 representation of the flip of these numbers. This gives us:

425 509 509 425 477 477 0 477 477 425 509 509 425


We can take the distinct values and index in at the indices we require:

q)509 425 477 0@1 0 0 1 2 2 3 2 2 1 0 0 1
425 509 509 425 477 477 0 477 477 425 509 509 425


This array 1 0 0 1 2 2 3 2 2 1 0 0 1 converted to base-4 is

q)k)4/:1 0 0 1 2 2 3 2 2 1 0 0 1
17218113


So for the solution, we are just doing these steps in reverse.

"x-| "@4\:509 425 477 0@4\:17218113 / the solution
4\:17218113 / convert 17218113 into base-4
509 425 477 0@            / index (@) into 509 425 477 0
4\:                          / convert to base-4
"x-| "@                             / index (@) into "x-| "


///, 46 bytes

/#/
!  x  !
//"/------//!/|  |/"x"#!--x--!#"x"


Try it online!

Vyxalj, 22 bytes

»°₈q8»|- τ3/\x+ømvøm


Try it Online!

Alternative 22 bytes

»ƛ\¶≤NV»x-| τ3/ømvøm
`

Try it Online!