Ayo bermain tenis


45

Tiba-tiba saya benar-benar ingin bermain tenis, tetapi sayangnya saya tidak memiliki lapangan!

Mengherankan! Ini adalah di mana Anda datang.

Anda harus mencetak lapangan tenis untuk saya, tetapi Anda harus melakukannya dalam byte sesedikit mungkin karena alasan rahasia.

Lapangan tenis

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

Ini adalah , jadi kode terpendek dalam byte menang!


1
Membuntuti baris baru diizinkan?
Erik the Outgolfer

1
Bisakah celah besar di baris 2 dan 8 dilakukan menggunakan tab?
FlipTack

3
@ Flp.Tkc, saya rasa tidak. Saya pikir karena tidak ada orang lain di keenam jawaban yang diposting tahu itu, itu tidak adil.
Daniel

2
Ini adalah tantangan yang sangat sulit untuk string keluaran pendek! Saya suka itu. :)
Lynn

7
Anda bisa menyebut tantangan ini sebagai "pengadilan Dennis" karena semua orang tahu siapa yang akan menang ... :)
RudolfJelin

Jawaban:



13

Python 2, 65 byte

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

Flp.Tkc menyimpan satu byte.


Itu beberapa irisan gila. Bagus!
Gurupad Mamadapur

Anda dapat menggunakan '|'+' '*7string kedua suntuk menghemat satu byte!
FlipTack

12

05AB1E ,29 27 26 byte

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

Cobalah 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

9'-×D'|4ð׫©ûs®¨'|«û5'x×»ûmencoba refactoring sedikit, tidak dapat merusak 26.
Magic Gurita Guci


7

Python 3 - 73 72 byte

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

Python 3.6 - 75 byte

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

Kredit jatuh ke flp-tkc . Terima kasih :)

Coba di sini!


6

/// , 64 56 byte

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

Cobalah online!

Solusi 56 byte lainnya:

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

6

V , 25 byte

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

Cobalah online!

Ini harus 23 byte:

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

Tetapi saya menemukan beberapa bug saat membuatnya. :(


6

Jelly , 25 byte

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

TryItOnline!

Saya berharap untuk menggunakan pengulangan pengadilan 1,3,1 kuartal, tetapi tidak bisa memerasnya menjadi kurang (versi mentah menjadi 28:) “ßṂuB’b4s3x“¢¤¢‘ị“- x|”ŒBŒḄY.

Bagaimana?

“¡⁵÷ḞȯḤɼ’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

5

J, 70 54 51 50 byte

Menyimpan satu byte berkat Zgarb!

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

Beberapa teknik kompresi standar, menggunakan RLE terkompresi.

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

Susun ulang dan simpan satu byte:9 9$'-| |-| | |x| | |'#~3 9 1 7{~4#.inv 1851926050
Zgarb

@ Zgarb ah, bagus!
Conor O'Brien

4

Ruby, 60 byte

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

Tidak disatukan

-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.

4

bash / alat Unix, 58 57 byte

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

Hanya empat karakter selain baris baru muncul dalam output yang diinginkan, yang memungkinkan setiap baris dikodekan sebagai nomor basis-4. Angka-angka ini kemudian ditulis dalam heksadesimal dalam skrip, untuk singkatnya.

Kalkulator Unix dc digunakan baik untuk konversi basis-16 ke basis-4 maupun manipulasi tumpukan untuk memudahkan pengulangan garis di tempat yang tepat.

Sunting: Memangkas satu byte dengan menukar dua digit basis-4 yang digunakan untuk mengkode karakter, memungkinkan perintah tr menjadi satu byte lebih pendek dari versi sebelumnya.


4

JavaScript, 85 byte

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

4

JavaScript (ES6), 86 84 83 81 byte

Disimpan 2 byte, terima kasih kepada 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))

You can make this a function to save a few bytes.
Conor O'Brien

@ConorO'Brien I'm not sure it's allowed to just return the output here: You have to print a tennis court
Arnauld

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

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

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

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.



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)


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


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.


1
Notices are turned off in the default config; no need for -d error_reporting=0, just use -n.
Titus

I count 66. You can make them 65 with <?=$a=($b="---------\n|")."....
Titus

@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

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.


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.


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(^)

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

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


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.

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.


$(' '*7) is actually 8 chars, would be shorter to just do | | as spaces.
colsw

@ConnorLSW Oh, haha. Thanks for the obvious golf! :D
AdmBorkBork

just paying you back for the ToLower() save on my other answer ;)
colsw

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])

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


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.


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.


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 

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

Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.