Let's play tennis

45

3

I suddenly really want to play tennis, but alas I do not have a court!

Surprise! This is where you come in.

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

Tennis court

---------
|       |
---------
|   |   |
xxxxxxxxx
|   |   |
---------
|       |
---------

This is , so shortest code in bytes wins!

Daniel

Posted 2016-12-18T21:37:08.730

Reputation: 6 425

1Trailing newline allowed? – Erik the Outgolfer – 2016-12-18T22:02:23.603

@ErikGolferエリックゴルファー yes – Daniel – 2016-12-18T22:06:59.653

1Can the large gaps in row 2 and 8 be done using tabs? – FlipTack – 2016-12-18T22:13:56.057

3@Flp.Tkc, I don't think so. I think since nobody else in the six answers already posted knew that, it would be unfair. – Daniel – 2016-12-18T22:25:07.443

Are extra spaces allowed (as long as the output looks like the picture)? – G B – 2016-12-19T11:46:44.710

@GB, extra spaces where? – Daniel – 2016-12-19T11:56:09.407

Extra spaces after the end of an output line (before newline). – G B – 2016-12-19T12:08:28.813

@GB, no. You may only have an optional trailing newline – Daniel – 2016-12-19T12:10:21.477

2This is a surprisingly tricky challenge for such a short output string! I like it. :) – Lynn – 2016-12-19T12:33:17.380

7You can just call this challenge a "Dennis court" since everybody knows who will win anyway... :) – RudolfJelin – 2016-12-19T19:31:39.240

133 votes, 33 answers... – FlipTack – 2016-12-22T19:55:06.770

@RudolfL.Jelínek Too early! DJMcMayhem won, in fact. – Erik the Outgolfer – 2016-12-29T08:03:45.323

@FlipTack 36 votes, 36 answers... – RudolfJelin – 2016-12-29T12:25:18.527

@RudolfL.Jelínek 40 votes, 40 answers now :) – adrianmp – 2017-02-25T21:17:20.540

Answers

1

Canvas, 13 bytes

A←⁹w5+7q⁴‟5n┼

Try it here!

dzaima

Posted 2016-12-18T21:37:08.730

Reputation: 19 048

13

Python 2, 65 bytes

s='-','|'+' '*7,'-','|   ','x'
for i in s+s[3::-1]:print(i*9)[:9]

Flp.Tkc saved a byte.

Lynn

Posted 2016-12-18T21:37:08.730

Reputation: 55 648

That's some crazy slicing. Nice! – Gurupad Mamadapur – 2016-12-19T14:14:41.513

You can use '|'+' '*7 for the second string in s to save a byte! – FlipTack – 2016-12-19T17:59:37.777

12

05AB1E, 29 27 26 bytes

'-9ש'|ð4׫Dûs®s¨¨ûû'x5×»û

Try it online!

'-9ש                      Push "---------" and store it as temporary value
     '|ð4׫Dûs             Push palindromized("|    ") = "|       |"
                           and push "|    "
              ®            Push "---------" again
               s¨¨û        Strip the last 2 characters from "|    " and push palindromized("|  ") = "|   |"
                   û       Palindromize last item -> "|   |   |"
                    'x5×   Push "xxxxx"
                        »  Join everything with newlines
                         û Palindromize the result and implicitly display it

Osable

Posted 2016-12-18T21:37:08.730

Reputation: 1 321

9'-×D'|4ð׫©ûs®¨'|«û5'x×»û tried refactoring a little, can't break 26. – Magic Octopus Urn – 2016-12-22T15:25:17.327

Another 26 bytes alternative.

– Kevin Cruijssen – 2018-11-01T13:37:10.517

7

Python 3 - 73 72 bytes

d=b,a,c='|       |','-'*9,'|   |   |'
print(a,*d,'x'*9,c,a,b,a,sep='\n')

Python 3.6 - 75 bytes

x=f"{'-'*9}\n|{' '*7}|\n{'-'*9}\n|   |   |\n"
print(x,'x'*9,x[::-1],sep='')

Credit goes to flp-tkc. Thank you :)

Try here!

Gurupad Mamadapur

Posted 2016-12-18T21:37:08.730

Reputation: 1 791

6

///, 64 56 bytes

/f/---//e/   //a/fff
|ee |
fff
//d/|e|e|
/adxxxxxxxxx
da

Try it online!

Another 56 byte solution:

/f/---//e/|   //a/fff
e    |
fff
//d/ee|
/adxxxxxxxxx
da

acrolith

Posted 2016-12-18T21:37:08.730

Reputation: 3 728

6

V, 25 bytes

9é-ÄÙÒ r|$.4äGMãlr|jj.kÒX

Try it online!

This should be 23 bytes:

9é-ÄÙÒ r|$.4äMÒXãkr|jj.

But I ran into several bugs while creating it. :(

James

Posted 2016-12-18T21:37:08.730

Reputation: 54 537

6

Jelly, 25 bytes

“¡⁵÷ḞȯḤɼ’b4ị“- x|”s5ŒBŒḄY

TryItOnline!

I had hoped to use the 1,3,1 quarter court repetition, but can't squeeze that into less (a raw version being 28: “ßṂuB’b4s3x“¢¤¢‘ị“- x|”ŒBŒḄY).

How?

“¡⁵÷ḞȯḤɼ’b4ị“- x|”s5ŒBŒḄY - Main link: no arguments
“¡⁵÷ḞȯḤɼ’                 - base 250 number: 375116358919167
         b4               - convert to base 4:
                                [1,1,1,1,1,0,2,2,2,2,1,1,1,1,1,0,2,2,2,0,3,3,3,3,3]
           ị“- x|”        - index into character list "- x|" (1-based):
                                "-----|    -----|   |xxxxx"
                  s5      - split into chunks of length 5:
                               ["-----","|    ","-----","|   |","xxxxx"]
                    ŒB    - bounce (vectorises):
                               ["---------","|        |","---------","|   |   |","xxxxxxxxx"]
                      ŒḄ  - bounce (non-vectorising version):
                               ["---------","|        |","---------","|   |   |","xxxxxxxxx","|   |   |","---------","|        |","---------"]
                        Y - join with line feeds:
                          - implicit print

Jonathan Allan

Posted 2016-12-18T21:37:08.730

Reputation: 67 804

5

J, 70 54 51 50 bytes

Saved a byte thanks to Zgarb!

9 9$'-| |-| | |x| | |'#~3 9 1 7{~4#.inv 1851926050

Some standard compression technique, using a compressed RLE.

   9 9$'-| |-| | |x| | |'#~3 9 1 7{~4#.inv 1851926050
---------
|       |
---------
|   |   |
xxxxxxxxx
|   |   |
---------
|       |
---------

Conor O'Brien

Posted 2016-12-18T21:37:08.730

Reputation: 36 228

Reorder and save a byte: 9 9$'-| |-| | |x| | |'#~3 9 1 7{~4#.inv 1851926050 – Zgarb – 2016-12-19T10:14:26.603

@Zgarb ah, nice! – Conor O'Brien – 2016-12-19T12:00:44.017

4

JavaScript (ES6), 86 84 83 81 bytes

Saved 2 bytes, thanks to Neil

a=`---------
`;a+=`|       |
`+a;b=`|   |   |
`;console.log(a+b+`xxxxxxxxx
`+b+a)

Alternate method #1, 93 bytes

console.log('01232101242421512424210123210'.replace(/./g,n=>`-
|  x`[n].repeat('911739'[n])))

Alternate method #2, 86 bytes

Suggested by Neil:

console.log(`-${s=`
       |
-
   |
`}x${s}-`.replace(/.*/g,s=>s.repeat(9).slice(-9)))

Alternate method #3, 91 bytes

A recursive approach:

console.log((f=(n,c=`xxxx
|   |   |
---------
|       |
`[n]||'-')=>~n--?c+f(n)+c:'x')(43))

Arnauld

Posted 2016-12-18T21:37:08.730

Reputation: 111 334

You can make this a function to save a few bytes. – Conor O'Brien – 2016-12-19T02:28:50.860

@ConorO'Brien I'm not sure it's allowed to just return the output here: You have to print a tennis court – Arnauld – 2016-12-19T09:50:00.650

Simple run length encoding is a byte shorter than your alternate method: console.log('-9\n| 7|\n-9\n| 3| 3|\nx9\n| 3| 3|\n-9\n| 7|\n-9'.replace(/.\d/g,s=>s[0].repeat(s[1]))) (replace \n with newline obviously). – Neil – 2016-12-19T10:23:12.437

Another 92-byte formulation: console.log('-\n |\n-\n |\nx\n |\n-\n |\n-'.replace(/.*/g,s=>s.repeat(9).slice(-9))). – Neil – 2016-12-19T10:28:20.297

Sorry, there are supposed to be 7 or 3 spaces before each | as appropriate instead of the single space that appears in my comment. – Neil – 2016-12-19T10:34:01.047

Oh, and just converting your main answer to separate statements saves 2 bytes, since you don't need the extra set of ()s. – Neil – 2016-12-19T10:40:15.000

@Neil I really like your repeat(9).slice(-9) idea! – Arnauld – 2016-12-19T10:45:59.490

I've since beaten those methods, even without ES6 features, so I've added it as a separate answer. – Neil – 2016-12-19T11:06:12.500

4

Ruby, 60 bytes

-4.upto(4){|i|puts''.rjust(9,%w{x |%3s - |%7s -}[i.abs]%'')}

Ungolfed

-4.upto(4){|i|                    #iterate -4 to 4.
   puts''.rjust(9,                #Print the null string right justified to length 9 padded by repititions of
   %w{x |%3s - |%7s -}[i.abs]%'') #the string from the %w{} array modified like sprintf by the % operator
}                                 #so that %Ns is replaced by N spaces.

Level River St

Posted 2016-12-18T21:37:08.730

Reputation: 22 049

4

bash/Unix tools, 58 57 bytes

dc<<<4o16i3FFFFp20002prp20202p15555pszpszfp|tr 0-3 ' x|-'

Only four characters other than newline appear in the desired output, allowing each line to be coded as a base-4 number. These numbers are then written in hexadecimal in the script, for brevity.

The Unix calculator dc is used both for the base-16 to base-4 conversion and for stack manipulation to allow easy repetition of lines in the right places.

Edit: Shaved one byte off by swapping two of the base-4 digits used to code characters, permitting the tr command to be one byte shorter than the previous version.

Mitchell Spector

Posted 2016-12-18T21:37:08.730

Reputation: 3 392

4

JavaScript, 85 bytes

console.log('---|  ---| |xxx| |---|  ---'.replace(/(.)((.).)/g,'$1$3$3$2$3$3$3$1\n'))

Neil

Posted 2016-12-18T21:37:08.730

Reputation: 95 035

4

SOGL 0.5, 24 23 20 bytes (non-competing)

 -9*"D√⅜‘⁴"Hοr‘¹q x9*o±

Explanation:

"'|⁶.f,‘9n_h¹q x9*o±
"'|⁶.f,‘              pushes "------------------|       ||   |   |"
        9n            splits into chunks of 9
                       stack: [["---------","---------","|       |","|   |   |"]]
          _           puts all the contents of the array into the stack
                       stack: ["---------","|       |","---------","|   |   |"]
           h          swaps the 2nd from top with 3rd from top
            ¹         turns back into array
                       stack: [["---------","|       |","---------","|   |   |"]]
             q        outputs the array without popping it from stack
               x      push "x"
                       stack: [["---------","|       |","---------","|   |   |"], "x"]
                9*    repeat it 9 times
                       stack: [["---------","|       |","---------","|   |   |"], "xxxxxxxxx"]
                  o   output that
                   ±  reverse the array
implicitly output the reversed array

So how does the compressed string work?

The string converted from base250 to binary is 1000000100111110010100001110100000001100010001

and approxametally what it does:

100 boxstring (a custom dictionary string with chars " -/\|_\n")
000010 choose only the "-"s
01111 with length of 15+(different chars used)+2 = 18 chars
there is only 1 char type, so results in "------------------"
100 another boxsting
101000 choosing " " and "|"
01110 with length of 14+(different chars used)+2 = 18 chars
100000001100010001 the data; 0 = " " and 1 = "|"
has "------------------" and "|       ||   |   |" and just joins them together

non-competing, because language postdates the challenge. And this challenge is only a day old. I knew I should've put something up yesterday. I did this as a test for my language and it ended up too good not to post. Pretty sure this is golfable more too.

dzaima

Posted 2016-12-18T21:37:08.730

Reputation: 19 048

3

///, 59 bytes

/_/---------
//s/   /_|ss |
_|s|s|
xxxxxxxxx
|s|s|
_|ss |
_

Try it online!

Outgolfed...

Erik the Outgolfer

Posted 2016-12-18T21:37:08.730

Reputation: 38 134

3

Javascript (ES6), 86 bytes:

a=`---------
|       |
---------`;b=`|   |   |
`;console.log(a+`
`+b+`xxxxxxxxx
`+b+a)

Test here:

a=`---------
|       |
---------`;b=`|   |   |
`;console.log(a+`
`+b+`xxxxxxxxx
`+b+a)

n4melyh4xor

Posted 2016-12-18T21:37:08.730

Reputation: 507

You can save 4 bytes by adding a newline at the start of b, as this means that you can remove the newline after xxxxxxxxx and the one that you add between a and b. You can save a further 3 bytes by setting a to --------- first and then concatenating the second row and a to itself. – Neil – 2016-12-19T10:15:39.363

3

05AB1E, 26 bytes

'-5ש'|4úD®sÂðñ)í€û»'x5×»û

Uses the CP-1252 encoding. Try it online!

Adnan

Posted 2016-12-18T21:37:08.730

Reputation: 41 965

Better golf this down more! – Oliver Ni – 2016-12-20T00:36:41.783

3

PHP, 66 62 bytes

This is the original answer (66 bytes):

<?=$a="---------
|       |
---------
|   |   |
xxxx",x,strrev($a);

It generates a notice because of the unknown constant x. The notice can be suppressed by setting error_reporting=0 in php.ini or in the command line:

$ php -d error_reporting=0 tennis.php

The last line of the output doesn't end with a newline character.


The updated answer (62 bytes), improving an improvement suggested by @Titus:

<?=$a=($b="---------
|   ")."    |
$b|   |
xxxx",x,strrev($a);

Run it without a configuration file (it defaults with error_reporting=0 this way):

$ php -n tennis.php

Both versions of the code contain literal new lines embedded in the string (1 byte shorter than \n) and cannot we unwrapped.

axiac

Posted 2016-12-18T21:37:08.730

Reputation: 749

1Notices are turned off in the default config; no need for -d error_reporting=0, just use -n. – Titus – 2016-12-21T06:19:46.377

I count 66. You can make them 65 with <?=$a=($b="---------\n|").".... – Titus – 2016-12-21T06:32:44.653

@Titus I like your suggestion. -n is much shorter than -d error_reporting=0 :-) There are, indeed, only 66 useful chars in the answer. I counted them using ls -l and forgot my vi is configured to ensure the file ends with a new line. I improved your improvement and squeezed 3 more bytes. Thank you. – axiac – 2016-12-21T08:21:48.700

2

Pyke, 28 26 25 bytes

\|ddsssd7*.X--||"R\x5*nJs

Try it here!

       d7*                -    " " * 7
          .X--||"         -   grid(^, corners="-", sides="-", left="|", right="|")
\|dds                     -     "|  "
     s                    -    palindromise(^)
      s                   -   palindromise(^)
                  \x5*    -   "x" * 5
                      nJ  -  "\n".join(^)
                        s - palindromise(^)

Blue

Posted 2016-12-18T21:37:08.730

Reputation: 26 661

2

Ruby, 52 bytes

puts [b=[a=?-*9,"|%8s"%?|,a],c="|   |   |",?x*9,c,b]

Using the double simmetry, the lines are: 0-1-0 / 2-3-2 / 0-1-0, the loop can be easily unrolled and the nested list is flattened on output.

G B

Posted 2016-12-18T21:37:08.730

Reputation: 11 099

2

J, 36 bytes

9$'-'([,(' '4}]),[,],'x',:])9$'|   '

This works on the REPL, which is the standard way of using J:

   9$'-'([,(' '4}]),[,],'x',:])9$'|   '
---------
|       |
---------
|   |   |
xxxxxxxxx
|   |   |
---------
|       |
---------

With 41 bytes, I can print the result to STDOUT:

echo 9$'-'([,(' '4}]),[,],'x',:])9$'|   '

Try it online!

Explanation

I construct the tennis court one row at a time.

9$'-'([,(' '4}]),[,],'x',:])9$'|   '
                            9$'|   '  The string repeated to length 9: y = '|   |   |'
  '-'(                     )          Apply this verb to x = '-' and y:
                     'x',:]            y with a row of 'x'-chars above it.
                                       This is a 2x9 matrix, and "," now works by
                                       prepending new rows to it.
                   ],                  Prepend another y.
                 [,                    Prepend x, which is repeated to a row of length 9.
        (' '4}]),                      Prepend y with 4th character replaced by a space.
      [,                               Prepend x again.
                                      Now we have this 6x9 matrix:
                                       ---------
                                       |       |
                                       ---------
                                       |   |   |
                                       xxxxxxxxx
                                       |   |   | 
9$                                    Repeat it to have 9 rows.

Zgarb

Posted 2016-12-18T21:37:08.730

Reputation: 39 083

2

PHP, 72 bytes

<?=$a="---------
",$b="|       |
$a",$c="|   |   |
","xxxxxxxxx
$c$a$b";

I almost hate it when it´s shorter like this than with calculating a little.

Titus

Posted 2016-12-18T21:37:08.730

Reputation: 13 814

2

PowerShell, 67 66 bytes

($a='-'*9)
($b="|       |")
$a
($c="|   "*2+"|")
'x'*9
$c
$a
$b
$a

Try it online!

Just some string multiplication, setting variables, and ensuring they're encapsulated in parens to place copies on the pipeline. The default Write-Output at program completion gives us newlines between for free.

Thanks to @ConnorLSW for saving an obvious byte.

AdmBorkBork

Posted 2016-12-18T21:37:08.730

Reputation: 41 581

$(' '*7) is actually 8 chars, would be shorter to just do | | as spaces. – colsw – 2017-02-24T11:27:39.573

@ConnorLSW Oh, haha. Thanks for the obvious golf! :D – AdmBorkBork – 2017-02-24T13:25:29.547

just paying you back for the ToLower() save on my other answer ;) – colsw – 2017-02-24T13:48:33.940

2

05AB1E, 25 bytes

'-9ש'|ð4׫û®…|  ûû'x5×»û

Uses the CP-1252 encoding. Try it online!

Explanation:

'-9×                       # Push "---------"
    ©                      # Store in register_c
     '|ð4׫                # Push "|    "
           û               # Palindromize, giving "|       |"
            ®              # Retrieve from register_c
             …|            # Push "|  "
                 ûû        # Palindromize twice, giving "|   |   |"
                   'x5×    # Push "xxxxx"
                       »   # Join by newlines
                        û  # Palindromize
                           # Implicit print

Oliver Ni

Posted 2016-12-18T21:37:08.730

Reputation: 9 650

2

Vim, 32 bytes

9i-^[Y3pO||^[7i ^[YGPkP4lr|YpO^[9ix^[

This will print the tennis court into a vim buffer. ^M represents the Enter key (0x0d) and ^[ is the Escape key (0x1b). You can run these keystrokes/code by saving them to a file and running

vim -s <filename> -u NONE

Printing to stdout

If it has to be printed to stdout instead, you could save the buffer to a file (I used "a") and use whichever shell vim is set to use (I used bash) as well as the cat program in order to print the tennis court to stdout (51 bytes):

9i-^[Y3pO||^[7i ^[YGPkP4lr|YpO^[9ix^[:w!a|sil !cat %^M:q^M

It's the same as the earlier version but with :w!a|sil !cat %^M:q^M added onto the end

sam

Posted 2016-12-18T21:37:08.730

Reputation: 21

1

Python 2, 75 bytes

a,b,c='-'*9,'|       |','|   |   |'
for e in[a,b,a,c,'x'*9,c,a,b,a]:print e

Uses variables borrowed from @GurupadMamadapur

Alternative also for 75

a,b,c='-'*9,'|       |','|   |   |'
print'\n'.join([a,b,a,c,'x'*9,c,a,b,a])

ElPedro

Posted 2016-12-18T21:37:08.730

Reputation: 5 301

1

Emacs, 43 35 keystrokes

M-9 x RET : nine x's, return
C-SPC : set mark
| M-3 SPC | M-3 SPC | RET : pipe, three spaces, pipe, three spaces, pipe, return
M-9 - RET : nine hyphens, return
| M-7 SPC | RET : pipe, seven spaces, pipe, return
M-9 - RET : nine hyphens, return
C-x C-x : exchange point and mark, selecting region
M-w : copy region
C-p : previous line
C-y : yank copied text
M-x rev-r RET : execute reverse-region command

Sean

Posted 2016-12-18T21:37:08.730

Reputation: 4 136

1

Lua, 82 Bytes.

y=[[---------
|       |
---------
]]z="|   |   |\n"io.write(y,z,"xxxxxxxxx\n",z,y)

I tried many methods, and yet this one proved the victor.

ATaco

Posted 2016-12-18T21:37:08.730

Reputation: 7 898

1

Pushy, 33 bytes

This question had 33 upvotes, and there were 33 answers, so I just had to post a 33 byte solution...

9:45;T`|    `wT`|   |`4dT5:120;w"

Try it online!


Explanation

The code can be split into several parts, to make it easier to understand. The first part works like so:

9:45;    \ Push the char '-' 9 times
T        \ Push 10, which is a linefeed
`|    `  \ Push these charcodes

The stack is now:

---------
|

The mirror operator, w, then mirrors the whole stack, producing:

---------
|       |
---------

Then:

T        \ Push a linefeed
`|   |`  \ Push these chars
4d       \ Copy the last 4 characters
T        \ Push a linefeed
5:120;   \ Push the char 'x', 5 times

The stack is now beginning to look like the tennis court:

---------
|       |
---------
|   |   |
xxxxx

To finish it, we use the mirror operator w once more, which reflects this string to produce the full tennis court.

---------
|       |
---------
|   |   |
xxxxxxxxx
|   |   |
---------
|       |
---------

All that's left now is to print, which is done by the " character.

FlipTack

Posted 2016-12-18T21:37:08.730

Reputation: 13 242

1

Unix Shell; using dc and tr; 55 Bytes: ( Optimization of Mitchell Spector solution )

dc<<<4o16i3FFFFp20002prp20202p15555psrfrp|tr 0-3 ' x|-'

Others Solutions : Using sed; 81 Bytes;

echo "---|  ---| |xxx| |---|  ---"|sed "s/\(.\)\(.\)\(.\)/\1\2\2\2\3\2\2\2\1\n/g"

Using dc in function : 88 Bytes

b(){ dc<<<2o16i1${1}p|tr '01' ' '$2;};(b FF -;b 01 \|;b FF -;b 11 \|)>f;cat f;b FF X;tac f

or

b(){ echo "obase=2;$1"|bc|tr '01' ' '$2;};(b 511 -;b 257 \|;b 511 -;b 273 \|)>f;cat f;b 511 X;tac f 

Using bc in function : 99 Bytes

b(){ echo "obase=2;$1"|bc|tr '01' ' '$2;};(b 511 -;b 257 \|;b 511 -;b 273 \|)>f;cat f;b 511 X;tac f 

Ali ISSA

Posted 2016-12-18T21:37:08.730

Reputation: 211

1

Powershell, 56 bytes

(('-'*9),'|       |'+'-'*9+'|   |   |'+'x'*9)[0..4+3..0]

Explanation: straightforward half-of-the-court

Alternative, 68 bytes

('-----','|    '+'-'*5+'|   |'+'x'*5)[($r=0..4+3..0)]|%{-join$_[$r]}

Explanation: quarter-of-the-court uses the same indexes for both row and column display

mazzy

Posted 2016-12-18T21:37:08.730

Reputation: 4 832

1

Python 2, 60 bytes

for i in 0,7,0,3,-2,3,0,7,0:print(('-?x|'[i%4]+' '*i)*9)[:9]

Try it online!

Uses Lynn's multiply-and-truncate method.

xnor

Posted 2016-12-18T21:37:08.730

Reputation: 115 687

0

Lua, 105 bytes

Sure, I've already been beaten, but it ain't fun if you don't try!

Actual answer:

a,c,d="---------","xxxxxxxxx","|   |   |"p=print p(a)p("|       |")p(a)p(d)p(c)p(d)p(a)p("|       |")p(a)

Less hardcoded:

a,b,c,d=("-"):rep(9),(" "):rep(7),("x"):rep(9),"|   |   |"p=print p(a)p("|"..b.."|")p(a)p(d)p(c)p(d)p(a)p("|"..b.."|")p(a)

Uses String.rep to make it less hardcoded (though it adds bytes!) (instead of xxxxxxxxx, write ("x"):rep(9))

Just for fun, how easy would it be to just print it hardcoded?

print([[---------
|       |
---------
|   |   |
xxxxxxxxx
|   |   |
---------
|       |
---------]])

100 bytes. That's shorter than my code. :(

devRicher

Posted 2016-12-18T21:37:08.730

Reputation: 1 609

Didn't checked the other ones, but the hardcoded version can be 98 characters if you remove the parenthesis: print[[…]]. – manatwork – 2016-12-19T10:16:21.250

But the 2 mirrored halves approach is of course shorter: http://pastebin.com/pJLFEuck

– manatwork – 2016-12-19T10:26:03.013

0

Batch, 116 bytes

@set s=---------
@for %%s in (%s% "|       |" %s% "|   |   |" %s:-=x% "|   |   |" %s% "|       |" %s%)do @echo %%~s

Conveniently, expansion of for variables happens after parsing, so I only have to quote the |s once. However, only the horizontal lines are sufficiently repetitive that using a variable saves bytes.

Neil

Posted 2016-12-18T21:37:08.730

Reputation: 95 035

0

Actually, 49 bytes

'x9*' 3*;2╟"|%s|%s|"%9'-*' 7*"|%s|"%9'-*k;RdX@i(i

Try it online!

Explanation:

'x9*' 3*;2╟"|%s|%s|"%9'-*' 7*"|%s|"%9'-*k;RdX@i(i
'x9*                                               "xxxxxxxxx"
    ' 3*;2╟"|%s|%s|"%                              "|   |   |"
                     '-*' 7*"|%s|"%                "|       |"
                                   9'-*            "---------"
                                       k;          push entire stack to list, duplicate it
                                         RdX       reverse one copy and remove the string of "x"s from it
                                            @i     flatten the other copy
                                              (i   flatten the first copy and implicitly print

Mego

Posted 2016-12-18T21:37:08.730

Reputation: 32 998

0

Scala, 90 bytes

val l="-"*9
val g="\n|       |\n"
val s="\n|   |   |\n"
print(l+g+l+s+"x"*9+s+l+g+l)

corvus_192

Posted 2016-12-18T21:37:08.730

Reputation: 1 889

0

MATL, 30 bytes

9Z"13+'|'7Z"yhhyy6M5(v'x'9Y"yP

Try it online!

Luis Mendo

Posted 2016-12-18T21:37:08.730

Reputation: 87 464

0

R, 121 bytes

m=rbind(a<-rep("-",9),b<-c("|",rep(" ",7),"|"),a,b,rep("x",9),b,a,b,a);m[c(4,6),5]="|";for(i in 1:9)cat(m[i,],"\n",sep="")

First time trying a Kolmogorov-Complexity challenge, not sure R is really suited for it.

Ungolfed:

a <- rep("-", 9)
b <- c("|", rep(" ", 7), "|")
m <- rbind(a, b, a, b, rep("x", 9), b, a, b, a)

m[c(4,6), 5] <- "|"

for(i in 1:9){
  cat(m[i,], "\n", sep = "")
}

Output:

---------
|       |
---------
|   |   |
xxxxxxxxx
|   |   |
---------
|       |
---------

JAD

Posted 2016-12-18T21:37:08.730

Reputation: 2 898

"|", rep(" ", 7), "|" is longer than "| ​ ​ ​ ​ ​ ​ |" – 12Me21 – 2017-02-23T21:25:25.893

@12Me21 The code as I use it now requires a vector with each of the spaces in a separate string :/ so this wouldn't work with a direct substitution. – JAD – 2017-02-24T22:15:51.207

This does make me realise though that this answer is longer than just printing the raw code. Ohwell... – JAD – 2017-02-24T22:16:51.033

0

Scala, 83 bytes

val(a,b)=("-"*9+"\n|   ","   |\n")  
val c=s"$a $b$a|$b"  
print(c+"x"*9+c.reverse)

Minimal

Posted 2016-12-18T21:37:08.730

Reputation: 131

0

C, 97 bytes

n=11;i,k;f(){i=n/10%10;k=n++%10;printf("%c",k?"| -x"[i%2?i==5|2:k%8-1&&k-5|i*i%5-1]:10);i?f():0;}

Steadybox

Posted 2016-12-18T21:37:08.730

Reputation: 15 798

0

///, 55 bytes

/l/---//s/   //m/
|s|s|
//a/lll
|s s|
lll/amxxxxxxxxxma

Try it online

Cedric Reichenbach

Posted 2016-12-18T21:37:08.730

Reputation: 448

0

Common Lisp, 90 86 85 81 79 bytes

(format t"~5@{~@?
~}~4@{~2:*~@?
~}"#1="~9@{-~}""|~8t|"#1#"|   |   |""~9@{x~}"1)

First we print out all arguments, and then we print them in reversed order (without xxxxxxxxx).

Similiar solution, but instead of providing every variable directly I give (where it's efficient) control string which will output needed text.

user65167

Posted 2016-12-18T21:37:08.730

Reputation:

0

SmileBASIC, 68 65 62 59 57 bytes

M$="|   
L$="-"*9?L$?M$,M$?L$?M$*3?"x"*9?M$*3?L$?M$,M$?L$

(note the 3 trailing spaces in line 1)

Of course, this will work in many other dialects of BASIC.

Explained:

V$="|   " 'vertical line
H$="-"*9 'horizontal line
PRINT H$    '---------
PRINT V$,V$ '|       |
PRINT H$    '---------
PRINT V$*3  '|   |   |
PRINT "x"*9 'xxxxxxxxx
PRINT V$*3  '|   |   |
PRINT H$    '---------
PRINT V$,V$ '|       |
PRINT H$    '---------

, in PRINT is a tab, and luckily the default size is perfect for this challenge.

12Me21

Posted 2016-12-18T21:37:08.730

Reputation: 6 110

0

Java 8, 98 bytes

Store repeated lines and add it all together.

()->{String a="---------\n",b="|       |\n",c="|   |   |\n";return a+b+a+c+"xxxxxxxxx\n"+c+a+b+a;}

NonlinearFruit

Posted 2016-12-18T21:37:08.730

Reputation: 5 334

0

C#, 88 bytes

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

Anonymous function which returns the tennis court as a string.

Full program with ungolfed method:

using System;

namespace LetsPlayTennis
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string> f =
            () =>
            {
                string a = "---------\n",
                    b = "|   |   |\n";
                return (a += "|\t|\n" + a)
                    + b
                    + "xxxxxxxxx\n"
                    + b
                    + a;
            };

            Console.WriteLine(f());
        }
    }
}

adrianmp

Posted 2016-12-18T21:37:08.730

Reputation: 1 592

0

Pip -l, 31 bytes

"--x--"M_X9WV:" || "M_WRsX3WR'|

Try it online!

Explanation

We construct the even rows, then the odd rows, and then weave them together.

"--x--"M_X9WV:" || "M_WRsX3WR'|
                                 s is space (implicit)
       M                         Map this function
"--x--"                          to each character of this string:
        _X9                       Repeat the character 9 times
                                 The result is a list of five 9-character strings

                    M            Map this function
              " || "             to each character of this string:
                     _            The character
                      WR          wrapped on each side in
                        sX3       three spaces
                           WR'|   wrapped on each side in |
                                 The result is a list of four 9-character strings

           WV:                   Weave the two lists together (the : helps with parsing)
                                 Print, with each list element on its own line (-l flag)

DLosc

Posted 2016-12-18T21:37:08.730

Reputation: 21 213

0

MBASIC, 89 bytes

1 WIDTH 13:P$="---------":S$="|       |":T$="|   |   |":PRINT $S$P$T$"xxxxxxxxx"T$P$S$P$

More abuse of the WIDTH directive to save multiple PRINTs.

wooshinyobject

Posted 2016-12-18T21:37:08.730

Reputation: 171

0

R, 76 bytes

"*"=strrep;write(c(a<-c(b<-"-"*9,"|       |",b,"|   |   |"),"x"*9,rev(a)),1)

Try it online!

J.Doe

Posted 2016-12-18T21:37:08.730

Reputation: 2 379