Relevant Part for a Badminton Serve
$begingroup$
Introduction:
I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here the second (first one can be found here):
Challenge:
Some rules about badminton serves:
- A serve will always be done diagonally over the net.
- You must always serve after the line that's parallel and nearest to the net.
- The area in which you are allowed to serve differs depending on whether it's a single (1 vs 1) or double/mix (2 vs 2).
- For singles (1 vs 1), the blue area in the picture below is where you are allowed to serve. So this is including the part at the back, but excluding the parts at the side.
- For doubles/mix (2 vs 2), the green area in the picture below is where you are allowed to server. So this is excluding the part at the back, but including the parts at the side.
- You may not stand on the lines when serving. But the shuttle will still be inside if they land on top of a line.
Here the layout of a badminton field:
Challenge rules:
Input:
You will be given two inputs:
- Something to indicate whether we're playing a single or double/mix (i.e. a boolean)
- Something to indicate which block you're serving from (i.e.
[1,2,3,4]
or['A','B','C','D']
as used in the picture above).
Output:
Only the relevant lines for the current serve (including the net), including an F
to indicate where you serve from, and multiple T
to indicate where you will potentially serve to.
Although in reality you're allowed to serve from and to anywhere in the designated areas, we assume a person that will serve will always stands in the corner of the serve area closes to the middle of the net, which is where you'll place the F
. And they will serve to any of the four corners of the area where they have to serve to, which is where you'll place the T
s.
As ASCII-art, the entire badminton field would be the following (the numbers are added so you don't have to count them yourself):
2 15 15 2
+--+---------------+---------------+--+
| | | | | 1
+--+---------------+---------------+--+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | 9
| | | | |
| | | | |
| | | | |
| | | | |
+--+---------------+---------------+--+
| | | | | 2
| | | | |
O=====================================O 37 times '='
| | | | |
| | | | | 2
+--+---------------+---------------+--+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | 9
| | | | |
| | | | |
| | | | |
| | | | |
+--+---------------+---------------+--+
| | | | | 1
+--+---------------+---------------+--+
Examples:
Here two examples for outputting only the relevant parts of the serve:
Input: Single and serve block A
Output:
T---------------T
| |
+---------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
T---------------T
| |
| |
O=====================================O
| |
| |
+---------------+
| F|
| |
| |
| |
| |
| |
| |
| |
| |
+---------------+
| |
+---------------+
As you can see, the F
is added in the corner within the block, but the T
are replacing the +
in the ASCI-art output.
Input: Double and serve block C
Output:
+--+---------------+
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | F|
+--+---------------+
| | |
| | |
O=====================================O
| | |
| | |
T---------------+--T
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
T---------------+--T
Challenge rules:
- Leading and trailing newlines are optional (including the leading and trailing two empty lines when the input is single). Trailing spaces are optional as well. Leading spaces are mandatory however.
- Any four reasonable distinct inputs to indicate which block we're serving from are allowed (for integers, stay within the [-999,999] range); as well as any two reasonable distinct inputs to indicate whether its a single or double/mix (please note this relevant forbidden loophole, though). Please state the I/O you've used in your answer!
- You are allowed to use a lowercase
f
andt
(or mixed case) instead ofF
andT
. - You are allowed to return a list of lines or matrix of characters instead of returning or printing a single output-string.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
code-golf string ascii-art
$endgroup$
|
show 1 more comment
$begingroup$
Introduction:
I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here the second (first one can be found here):
Challenge:
Some rules about badminton serves:
- A serve will always be done diagonally over the net.
- You must always serve after the line that's parallel and nearest to the net.
- The area in which you are allowed to serve differs depending on whether it's a single (1 vs 1) or double/mix (2 vs 2).
- For singles (1 vs 1), the blue area in the picture below is where you are allowed to serve. So this is including the part at the back, but excluding the parts at the side.
- For doubles/mix (2 vs 2), the green area in the picture below is where you are allowed to server. So this is excluding the part at the back, but including the parts at the side.
- You may not stand on the lines when serving. But the shuttle will still be inside if they land on top of a line.
Here the layout of a badminton field:
Challenge rules:
Input:
You will be given two inputs:
- Something to indicate whether we're playing a single or double/mix (i.e. a boolean)
- Something to indicate which block you're serving from (i.e.
[1,2,3,4]
or['A','B','C','D']
as used in the picture above).
Output:
Only the relevant lines for the current serve (including the net), including an F
to indicate where you serve from, and multiple T
to indicate where you will potentially serve to.
Although in reality you're allowed to serve from and to anywhere in the designated areas, we assume a person that will serve will always stands in the corner of the serve area closes to the middle of the net, which is where you'll place the F
. And they will serve to any of the four corners of the area where they have to serve to, which is where you'll place the T
s.
As ASCII-art, the entire badminton field would be the following (the numbers are added so you don't have to count them yourself):
2 15 15 2
+--+---------------+---------------+--+
| | | | | 1
+--+---------------+---------------+--+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | 9
| | | | |
| | | | |
| | | | |
| | | | |
+--+---------------+---------------+--+
| | | | | 2
| | | | |
O=====================================O 37 times '='
| | | | |
| | | | | 2
+--+---------------+---------------+--+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | 9
| | | | |
| | | | |
| | | | |
| | | | |
+--+---------------+---------------+--+
| | | | | 1
+--+---------------+---------------+--+
Examples:
Here two examples for outputting only the relevant parts of the serve:
Input: Single and serve block A
Output:
T---------------T
| |
+---------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
T---------------T
| |
| |
O=====================================O
| |
| |
+---------------+
| F|
| |
| |
| |
| |
| |
| |
| |
| |
+---------------+
| |
+---------------+
As you can see, the F
is added in the corner within the block, but the T
are replacing the +
in the ASCI-art output.
Input: Double and serve block C
Output:
+--+---------------+
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | F|
+--+---------------+
| | |
| | |
O=====================================O
| | |
| | |
T---------------+--T
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
T---------------+--T
Challenge rules:
- Leading and trailing newlines are optional (including the leading and trailing two empty lines when the input is single). Trailing spaces are optional as well. Leading spaces are mandatory however.
- Any four reasonable distinct inputs to indicate which block we're serving from are allowed (for integers, stay within the [-999,999] range); as well as any two reasonable distinct inputs to indicate whether its a single or double/mix (please note this relevant forbidden loophole, though). Please state the I/O you've used in your answer!
- You are allowed to use a lowercase
f
andt
(or mixed case) instead ofF
andT
. - You are allowed to return a list of lines or matrix of characters instead of returning or printing a single output-string.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
code-golf string ascii-art
$endgroup$
$begingroup$
Ah, badminton. The one game I’ve always wanted to play but never got around to because forgot/couldn’t find players to play with
$endgroup$
– Quintec
Apr 1 at 11:59
$begingroup$
@Quintec Feel free to come visit our club in The Netherlands for a free evening ;p
$endgroup$
– Kevin Cruijssen
Apr 1 at 12:20
1
$begingroup$
Deal, if you pay for my plane ticket and hotel? :)
$endgroup$
– Quintec
Apr 1 at 13:13
1
$begingroup$
@Quintec If you win, I'll pay the flight ticket back, haha xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 13:21
1
$begingroup$
@MagicOctopusUrn Yes, there are some professional badminton players from The Netherlands. Not sure what rank they have on the world list tbh, I don't watch badminton that often (and usually it's only 5 minutes on the sport news if mentioned at all anyway.. all other time is wasted with soccer). And no, as top player you might barely make an income I think. Definitely not millions.
$endgroup$
– Kevin Cruijssen
Apr 2 at 6:59
|
show 1 more comment
$begingroup$
Introduction:
I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here the second (first one can be found here):
Challenge:
Some rules about badminton serves:
- A serve will always be done diagonally over the net.
- You must always serve after the line that's parallel and nearest to the net.
- The area in which you are allowed to serve differs depending on whether it's a single (1 vs 1) or double/mix (2 vs 2).
- For singles (1 vs 1), the blue area in the picture below is where you are allowed to serve. So this is including the part at the back, but excluding the parts at the side.
- For doubles/mix (2 vs 2), the green area in the picture below is where you are allowed to server. So this is excluding the part at the back, but including the parts at the side.
- You may not stand on the lines when serving. But the shuttle will still be inside if they land on top of a line.
Here the layout of a badminton field:
Challenge rules:
Input:
You will be given two inputs:
- Something to indicate whether we're playing a single or double/mix (i.e. a boolean)
- Something to indicate which block you're serving from (i.e.
[1,2,3,4]
or['A','B','C','D']
as used in the picture above).
Output:
Only the relevant lines for the current serve (including the net), including an F
to indicate where you serve from, and multiple T
to indicate where you will potentially serve to.
Although in reality you're allowed to serve from and to anywhere in the designated areas, we assume a person that will serve will always stands in the corner of the serve area closes to the middle of the net, which is where you'll place the F
. And they will serve to any of the four corners of the area where they have to serve to, which is where you'll place the T
s.
As ASCII-art, the entire badminton field would be the following (the numbers are added so you don't have to count them yourself):
2 15 15 2
+--+---------------+---------------+--+
| | | | | 1
+--+---------------+---------------+--+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | 9
| | | | |
| | | | |
| | | | |
| | | | |
+--+---------------+---------------+--+
| | | | | 2
| | | | |
O=====================================O 37 times '='
| | | | |
| | | | | 2
+--+---------------+---------------+--+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | 9
| | | | |
| | | | |
| | | | |
| | | | |
+--+---------------+---------------+--+
| | | | | 1
+--+---------------+---------------+--+
Examples:
Here two examples for outputting only the relevant parts of the serve:
Input: Single and serve block A
Output:
T---------------T
| |
+---------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
T---------------T
| |
| |
O=====================================O
| |
| |
+---------------+
| F|
| |
| |
| |
| |
| |
| |
| |
| |
+---------------+
| |
+---------------+
As you can see, the F
is added in the corner within the block, but the T
are replacing the +
in the ASCI-art output.
Input: Double and serve block C
Output:
+--+---------------+
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | F|
+--+---------------+
| | |
| | |
O=====================================O
| | |
| | |
T---------------+--T
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
T---------------+--T
Challenge rules:
- Leading and trailing newlines are optional (including the leading and trailing two empty lines when the input is single). Trailing spaces are optional as well. Leading spaces are mandatory however.
- Any four reasonable distinct inputs to indicate which block we're serving from are allowed (for integers, stay within the [-999,999] range); as well as any two reasonable distinct inputs to indicate whether its a single or double/mix (please note this relevant forbidden loophole, though). Please state the I/O you've used in your answer!
- You are allowed to use a lowercase
f
andt
(or mixed case) instead ofF
andT
. - You are allowed to return a list of lines or matrix of characters instead of returning or printing a single output-string.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
code-golf string ascii-art
$endgroup$
Introduction:
I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here the second (first one can be found here):
Challenge:
Some rules about badminton serves:
- A serve will always be done diagonally over the net.
- You must always serve after the line that's parallel and nearest to the net.
- The area in which you are allowed to serve differs depending on whether it's a single (1 vs 1) or double/mix (2 vs 2).
- For singles (1 vs 1), the blue area in the picture below is where you are allowed to serve. So this is including the part at the back, but excluding the parts at the side.
- For doubles/mix (2 vs 2), the green area in the picture below is where you are allowed to server. So this is excluding the part at the back, but including the parts at the side.
- You may not stand on the lines when serving. But the shuttle will still be inside if they land on top of a line.
Here the layout of a badminton field:
Challenge rules:
Input:
You will be given two inputs:
- Something to indicate whether we're playing a single or double/mix (i.e. a boolean)
- Something to indicate which block you're serving from (i.e.
[1,2,3,4]
or['A','B','C','D']
as used in the picture above).
Output:
Only the relevant lines for the current serve (including the net), including an F
to indicate where you serve from, and multiple T
to indicate where you will potentially serve to.
Although in reality you're allowed to serve from and to anywhere in the designated areas, we assume a person that will serve will always stands in the corner of the serve area closes to the middle of the net, which is where you'll place the F
. And they will serve to any of the four corners of the area where they have to serve to, which is where you'll place the T
s.
As ASCII-art, the entire badminton field would be the following (the numbers are added so you don't have to count them yourself):
2 15 15 2
+--+---------------+---------------+--+
| | | | | 1
+--+---------------+---------------+--+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | 9
| | | | |
| | | | |
| | | | |
| | | | |
+--+---------------+---------------+--+
| | | | | 2
| | | | |
O=====================================O 37 times '='
| | | | |
| | | | | 2
+--+---------------+---------------+--+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | 9
| | | | |
| | | | |
| | | | |
| | | | |
+--+---------------+---------------+--+
| | | | | 1
+--+---------------+---------------+--+
Examples:
Here two examples for outputting only the relevant parts of the serve:
Input: Single and serve block A
Output:
T---------------T
| |
+---------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
T---------------T
| |
| |
O=====================================O
| |
| |
+---------------+
| F|
| |
| |
| |
| |
| |
| |
| |
| |
+---------------+
| |
+---------------+
As you can see, the F
is added in the corner within the block, but the T
are replacing the +
in the ASCI-art output.
Input: Double and serve block C
Output:
+--+---------------+
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | F|
+--+---------------+
| | |
| | |
O=====================================O
| | |
| | |
T---------------+--T
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
T---------------+--T
Challenge rules:
- Leading and trailing newlines are optional (including the leading and trailing two empty lines when the input is single). Trailing spaces are optional as well. Leading spaces are mandatory however.
- Any four reasonable distinct inputs to indicate which block we're serving from are allowed (for integers, stay within the [-999,999] range); as well as any two reasonable distinct inputs to indicate whether its a single or double/mix (please note this relevant forbidden loophole, though). Please state the I/O you've used in your answer!
- You are allowed to use a lowercase
f
andt
(or mixed case) instead ofF
andT
. - You are allowed to return a list of lines or matrix of characters instead of returning or printing a single output-string.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
code-golf string ascii-art
code-golf string ascii-art
edited Apr 1 at 8:15
Kevin Cruijssen
asked Apr 1 at 8:01
Kevin CruijssenKevin Cruijssen
42.6k571217
42.6k571217
$begingroup$
Ah, badminton. The one game I’ve always wanted to play but never got around to because forgot/couldn’t find players to play with
$endgroup$
– Quintec
Apr 1 at 11:59
$begingroup$
@Quintec Feel free to come visit our club in The Netherlands for a free evening ;p
$endgroup$
– Kevin Cruijssen
Apr 1 at 12:20
1
$begingroup$
Deal, if you pay for my plane ticket and hotel? :)
$endgroup$
– Quintec
Apr 1 at 13:13
1
$begingroup$
@Quintec If you win, I'll pay the flight ticket back, haha xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 13:21
1
$begingroup$
@MagicOctopusUrn Yes, there are some professional badminton players from The Netherlands. Not sure what rank they have on the world list tbh, I don't watch badminton that often (and usually it's only 5 minutes on the sport news if mentioned at all anyway.. all other time is wasted with soccer). And no, as top player you might barely make an income I think. Definitely not millions.
$endgroup$
– Kevin Cruijssen
Apr 2 at 6:59
|
show 1 more comment
$begingroup$
Ah, badminton. The one game I’ve always wanted to play but never got around to because forgot/couldn’t find players to play with
$endgroup$
– Quintec
Apr 1 at 11:59
$begingroup$
@Quintec Feel free to come visit our club in The Netherlands for a free evening ;p
$endgroup$
– Kevin Cruijssen
Apr 1 at 12:20
1
$begingroup$
Deal, if you pay for my plane ticket and hotel? :)
$endgroup$
– Quintec
Apr 1 at 13:13
1
$begingroup$
@Quintec If you win, I'll pay the flight ticket back, haha xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 13:21
1
$begingroup$
@MagicOctopusUrn Yes, there are some professional badminton players from The Netherlands. Not sure what rank they have on the world list tbh, I don't watch badminton that often (and usually it's only 5 minutes on the sport news if mentioned at all anyway.. all other time is wasted with soccer). And no, as top player you might barely make an income I think. Definitely not millions.
$endgroup$
– Kevin Cruijssen
Apr 2 at 6:59
$begingroup$
Ah, badminton. The one game I’ve always wanted to play but never got around to because forgot/couldn’t find players to play with
$endgroup$
– Quintec
Apr 1 at 11:59
$begingroup$
Ah, badminton. The one game I’ve always wanted to play but never got around to because forgot/couldn’t find players to play with
$endgroup$
– Quintec
Apr 1 at 11:59
$begingroup$
@Quintec Feel free to come visit our club in The Netherlands for a free evening ;p
$endgroup$
– Kevin Cruijssen
Apr 1 at 12:20
$begingroup$
@Quintec Feel free to come visit our club in The Netherlands for a free evening ;p
$endgroup$
– Kevin Cruijssen
Apr 1 at 12:20
1
1
$begingroup$
Deal, if you pay for my plane ticket and hotel? :)
$endgroup$
– Quintec
Apr 1 at 13:13
$begingroup$
Deal, if you pay for my plane ticket and hotel? :)
$endgroup$
– Quintec
Apr 1 at 13:13
1
1
$begingroup$
@Quintec If you win, I'll pay the flight ticket back, haha xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 13:21
$begingroup$
@Quintec If you win, I'll pay the flight ticket back, haha xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 13:21
1
1
$begingroup$
@MagicOctopusUrn Yes, there are some professional badminton players from The Netherlands. Not sure what rank they have on the world list tbh, I don't watch badminton that often (and usually it's only 5 minutes on the sport news if mentioned at all anyway.. all other time is wasted with soccer). And no, as top player you might barely make an income I think. Definitely not millions.
$endgroup$
– Kevin Cruijssen
Apr 2 at 6:59
$begingroup$
@MagicOctopusUrn Yes, there are some professional badminton players from The Netherlands. Not sure what rank they have on the world list tbh, I don't watch badminton that often (and usually it's only 5 minutes on the sport news if mentioned at all anyway.. all other time is wasted with soccer). And no, as top player you might barely make an income I think. Definitely not millions.
$endgroup$
– Kevin Cruijssen
Apr 2 at 6:59
|
show 1 more comment
4 Answers
4
active
oldest
votes
$begingroup$
Python 2, 285 284 bytes
R=str.replace
s,q=input()
A=' '*19
l='| '[s]+' |'+A[4:]+'|'+A
r=['T--+',' T'][s]+'-'*15+'T'+A
h=[r]+[l,R(r,*'T+')]*s+[l]*8+[l[:18]+'F'+'|'+A,r,l,l,'O'+'='*37+'O']
h+=[R(l[::-1],*'T+')for l in h[-2::-1]]
h[9+2*s]=R(h[9+2*s],*'F ')
for l in[l[::q%2*2-1]for l in h[::q/2*2-1]]:print l
Try it online!
Takes input as 0/1
(or False/True
) for game type (Double/Single
),
and 0-3
for serving block (0,1,2,3
= C,D,A,B
)
$endgroup$
$begingroup$
That was fast! Nice answer.
$endgroup$
– Kevin Cruijssen
Apr 1 at 8:20
1
$begingroup$
@Yeah, I kinda tried it from sandbox last week :P
$endgroup$
– TFeld
Apr 1 at 8:21
add a comment |
$begingroup$
Charcoal, 81 bytes
NθF⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ×=¹⁸O⟲O↙⁴J¹±³FF²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»F№ABη‖↑F№ACη‖
Try it online! Link is to verbose version of code. Takes the first input as 1
or 2
for singles or doubles, second input as one of ABCD
as in the question. Explanation:
F⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ
Loop over the relevant widths and the heights of the D
court and draw the rectangles.
×=¹⁸O⟲O↙⁴
Draw the net and apply rotational symmetry to add the A
court.
J¹±³F
Add the F
to the D
court.
F²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»
Add the T
s to the relevant places in the A
court.
F№ABη‖↑F№ACη‖
Reflect the output as necessary to serve from the correct court.
$endgroup$
1
$begingroup$
@KevinCruijssen Sorry for overlooking that, should be fixed now, thanks.
$endgroup$
– Neil
Apr 2 at 8:32
add a comment |
$begingroup$
JavaScript (ES7), 216 ... 205 201 199 bytes
Takes input as (block)(double)
, where block is either $-2$ (top right), $-1$ (bottom left), $1$ (bottom right) or $2$ (top left) and double is a Boolean value.
b=>d=>(g=x=>y<31?`+-| =OTF
`[X=x-19,Y=y-15,p=X*Y*b<0,q=Y>0^b&1,X*=X,Y*=Y,i=x*24%35>2|~16>>Y%62%6&2,x<39?Y?p*X|(d?Y:X-87)>169?3:i?X-1|Y-16|q?i:7:q*(d?X-87:Y)%169&&6:x%38?4:5:++y&&8]+g(-~x%40):'')(y=0)
Try it online!
Formatted version
How?
We iterate from $y=0$ to $y=30$ and from from $x=0$ to $x=39$ for each value of $y$.
We first define $X=x-19$ and $Y=y-15$.
The variables p = X * Y * b < 0
and q = Y > 0 ^ b & 1
are used to determine what do draw in each quarter according to the block $b$.
From now on, both $X$ and $Y$ are squared in order to easily test absolute positions within each quarter of the field.
The expression x * 24 % 35 > 2
yields false if $x$ belongs to ${0, 3, 19, 35, 38}$ (the positions of the vertical lines) or true otherwise.
Try it online!
The expression ~16 >> Y % 62 % 6 & 2
yields $0$ if $y$ belongs to ${0, 2, 12, 18, 28, 30}$ (the positions of the horizontal lines, excluding the net) or $2$ otherwise.
Try it online!
The variable $i$ is defined as the result of a bitwise OR between the two values above, and is therefore interpreted as:
- 3: space
- 2:
|
- 1:
-
- 0:
+
orT
The expression (d ? Y : X - 87) > 169
is used to crop the field according to the game type $d$ (single or double). The similar expression (d ? X - 87 : Y) % 169
is used to draw the T
's at the appropriate positions.
$endgroup$
$begingroup$
*Opens TIO and starts verifying the output* Looks good; all eight outputs are correct, as expected. *Looks at actual code* Huh.. wth is going on¿.. :S Looking forward to that explanation later on, @Arnauld. An unexpected amount of arithmetic, ternary, and bitwise calculations for an ASCII-art challenge. xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 17:29
1
$begingroup$
@KevinCruijssen Actually, I wish my formulas were even more freaky so that I could get this under 200 bytes, which was my initial target. ;) But my approach is probably too much optimized towards drawing the full field and not enough towards taking the parameters into account at a reasonable byte cost.
$endgroup$
– Arnauld
Apr 2 at 8:51
$begingroup$
Probably yeah, since I allowed any input-value in the range[-999,999]
for the four distinct inputs, so perhaps you could somehow use that to your advantage to golf some bytes. It would mean to partially start over, which is perhaps not be worth the effort. Unfortunately I can't give you any golfing tips to help you under 200 bytes; I can only wish you good luck in your attempts. ;p
$endgroup$
– Kevin Cruijssen
Apr 2 at 9:02
$begingroup$
@KevinCruijssen Done. :)
$endgroup$
– Arnauld
Apr 2 at 10:17
add a comment |
$begingroup$
Jelly, 108 99 bytes
“¢¥Þ‘Ṭ+þ³ḤN+“¢¤€‘¤ṬḤ;Ø0¤×3R¤¦€³+0x39¤µ‘03³?‘;20¤¦€1,-2¦;565DWx“¢%¢‘¤;UṚ$ị“|-+TO= ””F21¦€³Ḥ_⁵¤¦UṚƭ⁴¡
Try it online!
I’m sure this can be better golfed.
Dyadic link with left argument 0 or 1 for singles/doubles and right argument 0,1,2,3 for different serve quadrants. Returns a list of strings
Thanks to @KevinCruijssen for saving a byte!
$endgroup$
$begingroup$
I don't know Jelly, so I probably say something stupid here, but with“|-+TO= ”“F”
, can't the“F”
be golfed to another type of string for single characters? In 05AB1E for example, there are builtins for strings of size 1 ('
), 2 („
), or 3 (…
), so it could be'F
. Don't know if Jelly has something similar, or if you have another reason for it to be“|-+TO= ”“F”
?
$endgroup$
– Kevin Cruijssen
Apr 2 at 8:51
1
$begingroup$
@KevinCruijssen Thanks, and nice challenge. I don’t think so. There are two character literals (with ⁾), but not one. I could use a number 7 and add the F to the lookup, but it’s the same number of characters because of the need to follow the 7 with a 21 which therefore needs a space to separate the two.
$endgroup$
– Nick Kennedy
Apr 2 at 13:13
$begingroup$
Well, as I said, I don't know Jelly. Thought it might have some builtins for 1 or 2-character strings as well, but if you say not I believe you. :)
$endgroup$
– Kevin Cruijssen
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I’m happy for someone else to jump in - still learning!
$endgroup$
– Nick Kennedy
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I completely missed that”
could be used for a single character literal - oops! Thanks for saving a byte.
$endgroup$
– Nick Kennedy
7 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182496%2frelevant-part-for-a-badminton-serve%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 285 284 bytes
R=str.replace
s,q=input()
A=' '*19
l='| '[s]+' |'+A[4:]+'|'+A
r=['T--+',' T'][s]+'-'*15+'T'+A
h=[r]+[l,R(r,*'T+')]*s+[l]*8+[l[:18]+'F'+'|'+A,r,l,l,'O'+'='*37+'O']
h+=[R(l[::-1],*'T+')for l in h[-2::-1]]
h[9+2*s]=R(h[9+2*s],*'F ')
for l in[l[::q%2*2-1]for l in h[::q/2*2-1]]:print l
Try it online!
Takes input as 0/1
(or False/True
) for game type (Double/Single
),
and 0-3
for serving block (0,1,2,3
= C,D,A,B
)
$endgroup$
$begingroup$
That was fast! Nice answer.
$endgroup$
– Kevin Cruijssen
Apr 1 at 8:20
1
$begingroup$
@Yeah, I kinda tried it from sandbox last week :P
$endgroup$
– TFeld
Apr 1 at 8:21
add a comment |
$begingroup$
Python 2, 285 284 bytes
R=str.replace
s,q=input()
A=' '*19
l='| '[s]+' |'+A[4:]+'|'+A
r=['T--+',' T'][s]+'-'*15+'T'+A
h=[r]+[l,R(r,*'T+')]*s+[l]*8+[l[:18]+'F'+'|'+A,r,l,l,'O'+'='*37+'O']
h+=[R(l[::-1],*'T+')for l in h[-2::-1]]
h[9+2*s]=R(h[9+2*s],*'F ')
for l in[l[::q%2*2-1]for l in h[::q/2*2-1]]:print l
Try it online!
Takes input as 0/1
(or False/True
) for game type (Double/Single
),
and 0-3
for serving block (0,1,2,3
= C,D,A,B
)
$endgroup$
$begingroup$
That was fast! Nice answer.
$endgroup$
– Kevin Cruijssen
Apr 1 at 8:20
1
$begingroup$
@Yeah, I kinda tried it from sandbox last week :P
$endgroup$
– TFeld
Apr 1 at 8:21
add a comment |
$begingroup$
Python 2, 285 284 bytes
R=str.replace
s,q=input()
A=' '*19
l='| '[s]+' |'+A[4:]+'|'+A
r=['T--+',' T'][s]+'-'*15+'T'+A
h=[r]+[l,R(r,*'T+')]*s+[l]*8+[l[:18]+'F'+'|'+A,r,l,l,'O'+'='*37+'O']
h+=[R(l[::-1],*'T+')for l in h[-2::-1]]
h[9+2*s]=R(h[9+2*s],*'F ')
for l in[l[::q%2*2-1]for l in h[::q/2*2-1]]:print l
Try it online!
Takes input as 0/1
(or False/True
) for game type (Double/Single
),
and 0-3
for serving block (0,1,2,3
= C,D,A,B
)
$endgroup$
Python 2, 285 284 bytes
R=str.replace
s,q=input()
A=' '*19
l='| '[s]+' |'+A[4:]+'|'+A
r=['T--+',' T'][s]+'-'*15+'T'+A
h=[r]+[l,R(r,*'T+')]*s+[l]*8+[l[:18]+'F'+'|'+A,r,l,l,'O'+'='*37+'O']
h+=[R(l[::-1],*'T+')for l in h[-2::-1]]
h[9+2*s]=R(h[9+2*s],*'F ')
for l in[l[::q%2*2-1]for l in h[::q/2*2-1]]:print l
Try it online!
Takes input as 0/1
(or False/True
) for game type (Double/Single
),
and 0-3
for serving block (0,1,2,3
= C,D,A,B
)
edited Apr 1 at 16:35
answered Apr 1 at 8:17
TFeldTFeld
16.5k21451
16.5k21451
$begingroup$
That was fast! Nice answer.
$endgroup$
– Kevin Cruijssen
Apr 1 at 8:20
1
$begingroup$
@Yeah, I kinda tried it from sandbox last week :P
$endgroup$
– TFeld
Apr 1 at 8:21
add a comment |
$begingroup$
That was fast! Nice answer.
$endgroup$
– Kevin Cruijssen
Apr 1 at 8:20
1
$begingroup$
@Yeah, I kinda tried it from sandbox last week :P
$endgroup$
– TFeld
Apr 1 at 8:21
$begingroup$
That was fast! Nice answer.
$endgroup$
– Kevin Cruijssen
Apr 1 at 8:20
$begingroup$
That was fast! Nice answer.
$endgroup$
– Kevin Cruijssen
Apr 1 at 8:20
1
1
$begingroup$
@Yeah, I kinda tried it from sandbox last week :P
$endgroup$
– TFeld
Apr 1 at 8:21
$begingroup$
@Yeah, I kinda tried it from sandbox last week :P
$endgroup$
– TFeld
Apr 1 at 8:21
add a comment |
$begingroup$
Charcoal, 81 bytes
NθF⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ×=¹⁸O⟲O↙⁴J¹±³FF²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»F№ABη‖↑F№ACη‖
Try it online! Link is to verbose version of code. Takes the first input as 1
or 2
for singles or doubles, second input as one of ABCD
as in the question. Explanation:
F⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ
Loop over the relevant widths and the heights of the D
court and draw the rectangles.
×=¹⁸O⟲O↙⁴
Draw the net and apply rotational symmetry to add the A
court.
J¹±³F
Add the F
to the D
court.
F²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»
Add the T
s to the relevant places in the A
court.
F№ABη‖↑F№ACη‖
Reflect the output as necessary to serve from the correct court.
$endgroup$
1
$begingroup$
@KevinCruijssen Sorry for overlooking that, should be fixed now, thanks.
$endgroup$
– Neil
Apr 2 at 8:32
add a comment |
$begingroup$
Charcoal, 81 bytes
NθF⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ×=¹⁸O⟲O↙⁴J¹±³FF²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»F№ABη‖↑F№ACη‖
Try it online! Link is to verbose version of code. Takes the first input as 1
or 2
for singles or doubles, second input as one of ABCD
as in the question. Explanation:
F⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ
Loop over the relevant widths and the heights of the D
court and draw the rectangles.
×=¹⁸O⟲O↙⁴
Draw the net and apply rotational symmetry to add the A
court.
J¹±³F
Add the F
to the D
court.
F²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»
Add the T
s to the relevant places in the A
court.
F№ABη‖↑F№ACη‖
Reflect the output as necessary to serve from the correct court.
$endgroup$
1
$begingroup$
@KevinCruijssen Sorry for overlooking that, should be fixed now, thanks.
$endgroup$
– Neil
Apr 2 at 8:32
add a comment |
$begingroup$
Charcoal, 81 bytes
NθF⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ×=¹⁸O⟲O↙⁴J¹±³FF²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»F№ABη‖↑F№ACη‖
Try it online! Link is to verbose version of code. Takes the first input as 1
or 2
for singles or doubles, second input as one of ABCD
as in the question. Explanation:
F⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ
Loop over the relevant widths and the heights of the D
court and draw the rectangles.
×=¹⁸O⟲O↙⁴
Draw the net and apply rotational symmetry to add the A
court.
J¹±³F
Add the F
to the D
court.
F²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»
Add the T
s to the relevant places in the A
court.
F№ABη‖↑F№ACη‖
Reflect the output as necessary to serve from the correct court.
$endgroup$
Charcoal, 81 bytes
NθF⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ×=¹⁸O⟲O↙⁴J¹±³FF²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»F№ABη‖↑F№ACη‖
Try it online! Link is to verbose version of code. Takes the first input as 1
or 2
for singles or doubles, second input as one of ABCD
as in the question. Explanation:
F⮌Eθ⁺¹⁶׳ιF✂541⊖θURι±×³Iκ
Loop over the relevant widths and the heights of the D
court and draw the rectangles.
×=¹⁸O⟲O↙⁴
Draw the net and apply rotational symmetry to add the A
court.
J¹±³F
Add the F
to the D
court.
F²F²«J×ι±⁺¹²×³θ⁺²×⁻¹⁵׳θκT»
Add the T
s to the relevant places in the A
court.
F№ABη‖↑F№ACη‖
Reflect the output as necessary to serve from the correct court.
edited Apr 2 at 8:32
answered Apr 1 at 19:27
NeilNeil
82.7k745179
82.7k745179
1
$begingroup$
@KevinCruijssen Sorry for overlooking that, should be fixed now, thanks.
$endgroup$
– Neil
Apr 2 at 8:32
add a comment |
1
$begingroup$
@KevinCruijssen Sorry for overlooking that, should be fixed now, thanks.
$endgroup$
– Neil
Apr 2 at 8:32
1
1
$begingroup$
@KevinCruijssen Sorry for overlooking that, should be fixed now, thanks.
$endgroup$
– Neil
Apr 2 at 8:32
$begingroup$
@KevinCruijssen Sorry for overlooking that, should be fixed now, thanks.
$endgroup$
– Neil
Apr 2 at 8:32
add a comment |
$begingroup$
JavaScript (ES7), 216 ... 205 201 199 bytes
Takes input as (block)(double)
, where block is either $-2$ (top right), $-1$ (bottom left), $1$ (bottom right) or $2$ (top left) and double is a Boolean value.
b=>d=>(g=x=>y<31?`+-| =OTF
`[X=x-19,Y=y-15,p=X*Y*b<0,q=Y>0^b&1,X*=X,Y*=Y,i=x*24%35>2|~16>>Y%62%6&2,x<39?Y?p*X|(d?Y:X-87)>169?3:i?X-1|Y-16|q?i:7:q*(d?X-87:Y)%169&&6:x%38?4:5:++y&&8]+g(-~x%40):'')(y=0)
Try it online!
Formatted version
How?
We iterate from $y=0$ to $y=30$ and from from $x=0$ to $x=39$ for each value of $y$.
We first define $X=x-19$ and $Y=y-15$.
The variables p = X * Y * b < 0
and q = Y > 0 ^ b & 1
are used to determine what do draw in each quarter according to the block $b$.
From now on, both $X$ and $Y$ are squared in order to easily test absolute positions within each quarter of the field.
The expression x * 24 % 35 > 2
yields false if $x$ belongs to ${0, 3, 19, 35, 38}$ (the positions of the vertical lines) or true otherwise.
Try it online!
The expression ~16 >> Y % 62 % 6 & 2
yields $0$ if $y$ belongs to ${0, 2, 12, 18, 28, 30}$ (the positions of the horizontal lines, excluding the net) or $2$ otherwise.
Try it online!
The variable $i$ is defined as the result of a bitwise OR between the two values above, and is therefore interpreted as:
- 3: space
- 2:
|
- 1:
-
- 0:
+
orT
The expression (d ? Y : X - 87) > 169
is used to crop the field according to the game type $d$ (single or double). The similar expression (d ? X - 87 : Y) % 169
is used to draw the T
's at the appropriate positions.
$endgroup$
$begingroup$
*Opens TIO and starts verifying the output* Looks good; all eight outputs are correct, as expected. *Looks at actual code* Huh.. wth is going on¿.. :S Looking forward to that explanation later on, @Arnauld. An unexpected amount of arithmetic, ternary, and bitwise calculations for an ASCII-art challenge. xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 17:29
1
$begingroup$
@KevinCruijssen Actually, I wish my formulas were even more freaky so that I could get this under 200 bytes, which was my initial target. ;) But my approach is probably too much optimized towards drawing the full field and not enough towards taking the parameters into account at a reasonable byte cost.
$endgroup$
– Arnauld
Apr 2 at 8:51
$begingroup$
Probably yeah, since I allowed any input-value in the range[-999,999]
for the four distinct inputs, so perhaps you could somehow use that to your advantage to golf some bytes. It would mean to partially start over, which is perhaps not be worth the effort. Unfortunately I can't give you any golfing tips to help you under 200 bytes; I can only wish you good luck in your attempts. ;p
$endgroup$
– Kevin Cruijssen
Apr 2 at 9:02
$begingroup$
@KevinCruijssen Done. :)
$endgroup$
– Arnauld
Apr 2 at 10:17
add a comment |
$begingroup$
JavaScript (ES7), 216 ... 205 201 199 bytes
Takes input as (block)(double)
, where block is either $-2$ (top right), $-1$ (bottom left), $1$ (bottom right) or $2$ (top left) and double is a Boolean value.
b=>d=>(g=x=>y<31?`+-| =OTF
`[X=x-19,Y=y-15,p=X*Y*b<0,q=Y>0^b&1,X*=X,Y*=Y,i=x*24%35>2|~16>>Y%62%6&2,x<39?Y?p*X|(d?Y:X-87)>169?3:i?X-1|Y-16|q?i:7:q*(d?X-87:Y)%169&&6:x%38?4:5:++y&&8]+g(-~x%40):'')(y=0)
Try it online!
Formatted version
How?
We iterate from $y=0$ to $y=30$ and from from $x=0$ to $x=39$ for each value of $y$.
We first define $X=x-19$ and $Y=y-15$.
The variables p = X * Y * b < 0
and q = Y > 0 ^ b & 1
are used to determine what do draw in each quarter according to the block $b$.
From now on, both $X$ and $Y$ are squared in order to easily test absolute positions within each quarter of the field.
The expression x * 24 % 35 > 2
yields false if $x$ belongs to ${0, 3, 19, 35, 38}$ (the positions of the vertical lines) or true otherwise.
Try it online!
The expression ~16 >> Y % 62 % 6 & 2
yields $0$ if $y$ belongs to ${0, 2, 12, 18, 28, 30}$ (the positions of the horizontal lines, excluding the net) or $2$ otherwise.
Try it online!
The variable $i$ is defined as the result of a bitwise OR between the two values above, and is therefore interpreted as:
- 3: space
- 2:
|
- 1:
-
- 0:
+
orT
The expression (d ? Y : X - 87) > 169
is used to crop the field according to the game type $d$ (single or double). The similar expression (d ? X - 87 : Y) % 169
is used to draw the T
's at the appropriate positions.
$endgroup$
$begingroup$
*Opens TIO and starts verifying the output* Looks good; all eight outputs are correct, as expected. *Looks at actual code* Huh.. wth is going on¿.. :S Looking forward to that explanation later on, @Arnauld. An unexpected amount of arithmetic, ternary, and bitwise calculations for an ASCII-art challenge. xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 17:29
1
$begingroup$
@KevinCruijssen Actually, I wish my formulas were even more freaky so that I could get this under 200 bytes, which was my initial target. ;) But my approach is probably too much optimized towards drawing the full field and not enough towards taking the parameters into account at a reasonable byte cost.
$endgroup$
– Arnauld
Apr 2 at 8:51
$begingroup$
Probably yeah, since I allowed any input-value in the range[-999,999]
for the four distinct inputs, so perhaps you could somehow use that to your advantage to golf some bytes. It would mean to partially start over, which is perhaps not be worth the effort. Unfortunately I can't give you any golfing tips to help you under 200 bytes; I can only wish you good luck in your attempts. ;p
$endgroup$
– Kevin Cruijssen
Apr 2 at 9:02
$begingroup$
@KevinCruijssen Done. :)
$endgroup$
– Arnauld
Apr 2 at 10:17
add a comment |
$begingroup$
JavaScript (ES7), 216 ... 205 201 199 bytes
Takes input as (block)(double)
, where block is either $-2$ (top right), $-1$ (bottom left), $1$ (bottom right) or $2$ (top left) and double is a Boolean value.
b=>d=>(g=x=>y<31?`+-| =OTF
`[X=x-19,Y=y-15,p=X*Y*b<0,q=Y>0^b&1,X*=X,Y*=Y,i=x*24%35>2|~16>>Y%62%6&2,x<39?Y?p*X|(d?Y:X-87)>169?3:i?X-1|Y-16|q?i:7:q*(d?X-87:Y)%169&&6:x%38?4:5:++y&&8]+g(-~x%40):'')(y=0)
Try it online!
Formatted version
How?
We iterate from $y=0$ to $y=30$ and from from $x=0$ to $x=39$ for each value of $y$.
We first define $X=x-19$ and $Y=y-15$.
The variables p = X * Y * b < 0
and q = Y > 0 ^ b & 1
are used to determine what do draw in each quarter according to the block $b$.
From now on, both $X$ and $Y$ are squared in order to easily test absolute positions within each quarter of the field.
The expression x * 24 % 35 > 2
yields false if $x$ belongs to ${0, 3, 19, 35, 38}$ (the positions of the vertical lines) or true otherwise.
Try it online!
The expression ~16 >> Y % 62 % 6 & 2
yields $0$ if $y$ belongs to ${0, 2, 12, 18, 28, 30}$ (the positions of the horizontal lines, excluding the net) or $2$ otherwise.
Try it online!
The variable $i$ is defined as the result of a bitwise OR between the two values above, and is therefore interpreted as:
- 3: space
- 2:
|
- 1:
-
- 0:
+
orT
The expression (d ? Y : X - 87) > 169
is used to crop the field according to the game type $d$ (single or double). The similar expression (d ? X - 87 : Y) % 169
is used to draw the T
's at the appropriate positions.
$endgroup$
JavaScript (ES7), 216 ... 205 201 199 bytes
Takes input as (block)(double)
, where block is either $-2$ (top right), $-1$ (bottom left), $1$ (bottom right) or $2$ (top left) and double is a Boolean value.
b=>d=>(g=x=>y<31?`+-| =OTF
`[X=x-19,Y=y-15,p=X*Y*b<0,q=Y>0^b&1,X*=X,Y*=Y,i=x*24%35>2|~16>>Y%62%6&2,x<39?Y?p*X|(d?Y:X-87)>169?3:i?X-1|Y-16|q?i:7:q*(d?X-87:Y)%169&&6:x%38?4:5:++y&&8]+g(-~x%40):'')(y=0)
Try it online!
Formatted version
How?
We iterate from $y=0$ to $y=30$ and from from $x=0$ to $x=39$ for each value of $y$.
We first define $X=x-19$ and $Y=y-15$.
The variables p = X * Y * b < 0
and q = Y > 0 ^ b & 1
are used to determine what do draw in each quarter according to the block $b$.
From now on, both $X$ and $Y$ are squared in order to easily test absolute positions within each quarter of the field.
The expression x * 24 % 35 > 2
yields false if $x$ belongs to ${0, 3, 19, 35, 38}$ (the positions of the vertical lines) or true otherwise.
Try it online!
The expression ~16 >> Y % 62 % 6 & 2
yields $0$ if $y$ belongs to ${0, 2, 12, 18, 28, 30}$ (the positions of the horizontal lines, excluding the net) or $2$ otherwise.
Try it online!
The variable $i$ is defined as the result of a bitwise OR between the two values above, and is therefore interpreted as:
- 3: space
- 2:
|
- 1:
-
- 0:
+
orT
The expression (d ? Y : X - 87) > 169
is used to crop the field according to the game type $d$ (single or double). The similar expression (d ? X - 87 : Y) % 169
is used to draw the T
's at the appropriate positions.
edited Apr 2 at 11:03
answered Apr 1 at 17:10
ArnauldArnauld
80.7k797334
80.7k797334
$begingroup$
*Opens TIO and starts verifying the output* Looks good; all eight outputs are correct, as expected. *Looks at actual code* Huh.. wth is going on¿.. :S Looking forward to that explanation later on, @Arnauld. An unexpected amount of arithmetic, ternary, and bitwise calculations for an ASCII-art challenge. xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 17:29
1
$begingroup$
@KevinCruijssen Actually, I wish my formulas were even more freaky so that I could get this under 200 bytes, which was my initial target. ;) But my approach is probably too much optimized towards drawing the full field and not enough towards taking the parameters into account at a reasonable byte cost.
$endgroup$
– Arnauld
Apr 2 at 8:51
$begingroup$
Probably yeah, since I allowed any input-value in the range[-999,999]
for the four distinct inputs, so perhaps you could somehow use that to your advantage to golf some bytes. It would mean to partially start over, which is perhaps not be worth the effort. Unfortunately I can't give you any golfing tips to help you under 200 bytes; I can only wish you good luck in your attempts. ;p
$endgroup$
– Kevin Cruijssen
Apr 2 at 9:02
$begingroup$
@KevinCruijssen Done. :)
$endgroup$
– Arnauld
Apr 2 at 10:17
add a comment |
$begingroup$
*Opens TIO and starts verifying the output* Looks good; all eight outputs are correct, as expected. *Looks at actual code* Huh.. wth is going on¿.. :S Looking forward to that explanation later on, @Arnauld. An unexpected amount of arithmetic, ternary, and bitwise calculations for an ASCII-art challenge. xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 17:29
1
$begingroup$
@KevinCruijssen Actually, I wish my formulas were even more freaky so that I could get this under 200 bytes, which was my initial target. ;) But my approach is probably too much optimized towards drawing the full field and not enough towards taking the parameters into account at a reasonable byte cost.
$endgroup$
– Arnauld
Apr 2 at 8:51
$begingroup$
Probably yeah, since I allowed any input-value in the range[-999,999]
for the four distinct inputs, so perhaps you could somehow use that to your advantage to golf some bytes. It would mean to partially start over, which is perhaps not be worth the effort. Unfortunately I can't give you any golfing tips to help you under 200 bytes; I can only wish you good luck in your attempts. ;p
$endgroup$
– Kevin Cruijssen
Apr 2 at 9:02
$begingroup$
@KevinCruijssen Done. :)
$endgroup$
– Arnauld
Apr 2 at 10:17
$begingroup$
*Opens TIO and starts verifying the output* Looks good; all eight outputs are correct, as expected. *Looks at actual code* Huh.. wth is going on¿.. :S Looking forward to that explanation later on, @Arnauld. An unexpected amount of arithmetic, ternary, and bitwise calculations for an ASCII-art challenge. xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 17:29
$begingroup$
*Opens TIO and starts verifying the output* Looks good; all eight outputs are correct, as expected. *Looks at actual code* Huh.. wth is going on¿.. :S Looking forward to that explanation later on, @Arnauld. An unexpected amount of arithmetic, ternary, and bitwise calculations for an ASCII-art challenge. xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 17:29
1
1
$begingroup$
@KevinCruijssen Actually, I wish my formulas were even more freaky so that I could get this under 200 bytes, which was my initial target. ;) But my approach is probably too much optimized towards drawing the full field and not enough towards taking the parameters into account at a reasonable byte cost.
$endgroup$
– Arnauld
Apr 2 at 8:51
$begingroup$
@KevinCruijssen Actually, I wish my formulas were even more freaky so that I could get this under 200 bytes, which was my initial target. ;) But my approach is probably too much optimized towards drawing the full field and not enough towards taking the parameters into account at a reasonable byte cost.
$endgroup$
– Arnauld
Apr 2 at 8:51
$begingroup$
Probably yeah, since I allowed any input-value in the range
[-999,999]
for the four distinct inputs, so perhaps you could somehow use that to your advantage to golf some bytes. It would mean to partially start over, which is perhaps not be worth the effort. Unfortunately I can't give you any golfing tips to help you under 200 bytes; I can only wish you good luck in your attempts. ;p$endgroup$
– Kevin Cruijssen
Apr 2 at 9:02
$begingroup$
Probably yeah, since I allowed any input-value in the range
[-999,999]
for the four distinct inputs, so perhaps you could somehow use that to your advantage to golf some bytes. It would mean to partially start over, which is perhaps not be worth the effort. Unfortunately I can't give you any golfing tips to help you under 200 bytes; I can only wish you good luck in your attempts. ;p$endgroup$
– Kevin Cruijssen
Apr 2 at 9:02
$begingroup$
@KevinCruijssen Done. :)
$endgroup$
– Arnauld
Apr 2 at 10:17
$begingroup$
@KevinCruijssen Done. :)
$endgroup$
– Arnauld
Apr 2 at 10:17
add a comment |
$begingroup$
Jelly, 108 99 bytes
“¢¥Þ‘Ṭ+þ³ḤN+“¢¤€‘¤ṬḤ;Ø0¤×3R¤¦€³+0x39¤µ‘03³?‘;20¤¦€1,-2¦;565DWx“¢%¢‘¤;UṚ$ị“|-+TO= ””F21¦€³Ḥ_⁵¤¦UṚƭ⁴¡
Try it online!
I’m sure this can be better golfed.
Dyadic link with left argument 0 or 1 for singles/doubles and right argument 0,1,2,3 for different serve quadrants. Returns a list of strings
Thanks to @KevinCruijssen for saving a byte!
$endgroup$
$begingroup$
I don't know Jelly, so I probably say something stupid here, but with“|-+TO= ”“F”
, can't the“F”
be golfed to another type of string for single characters? In 05AB1E for example, there are builtins for strings of size 1 ('
), 2 („
), or 3 (…
), so it could be'F
. Don't know if Jelly has something similar, or if you have another reason for it to be“|-+TO= ”“F”
?
$endgroup$
– Kevin Cruijssen
Apr 2 at 8:51
1
$begingroup$
@KevinCruijssen Thanks, and nice challenge. I don’t think so. There are two character literals (with ⁾), but not one. I could use a number 7 and add the F to the lookup, but it’s the same number of characters because of the need to follow the 7 with a 21 which therefore needs a space to separate the two.
$endgroup$
– Nick Kennedy
Apr 2 at 13:13
$begingroup$
Well, as I said, I don't know Jelly. Thought it might have some builtins for 1 or 2-character strings as well, but if you say not I believe you. :)
$endgroup$
– Kevin Cruijssen
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I’m happy for someone else to jump in - still learning!
$endgroup$
– Nick Kennedy
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I completely missed that”
could be used for a single character literal - oops! Thanks for saving a byte.
$endgroup$
– Nick Kennedy
7 hours ago
add a comment |
$begingroup$
Jelly, 108 99 bytes
“¢¥Þ‘Ṭ+þ³ḤN+“¢¤€‘¤ṬḤ;Ø0¤×3R¤¦€³+0x39¤µ‘03³?‘;20¤¦€1,-2¦;565DWx“¢%¢‘¤;UṚ$ị“|-+TO= ””F21¦€³Ḥ_⁵¤¦UṚƭ⁴¡
Try it online!
I’m sure this can be better golfed.
Dyadic link with left argument 0 or 1 for singles/doubles and right argument 0,1,2,3 for different serve quadrants. Returns a list of strings
Thanks to @KevinCruijssen for saving a byte!
$endgroup$
$begingroup$
I don't know Jelly, so I probably say something stupid here, but with“|-+TO= ”“F”
, can't the“F”
be golfed to another type of string for single characters? In 05AB1E for example, there are builtins for strings of size 1 ('
), 2 („
), or 3 (…
), so it could be'F
. Don't know if Jelly has something similar, or if you have another reason for it to be“|-+TO= ”“F”
?
$endgroup$
– Kevin Cruijssen
Apr 2 at 8:51
1
$begingroup$
@KevinCruijssen Thanks, and nice challenge. I don’t think so. There are two character literals (with ⁾), but not one. I could use a number 7 and add the F to the lookup, but it’s the same number of characters because of the need to follow the 7 with a 21 which therefore needs a space to separate the two.
$endgroup$
– Nick Kennedy
Apr 2 at 13:13
$begingroup$
Well, as I said, I don't know Jelly. Thought it might have some builtins for 1 or 2-character strings as well, but if you say not I believe you. :)
$endgroup$
– Kevin Cruijssen
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I’m happy for someone else to jump in - still learning!
$endgroup$
– Nick Kennedy
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I completely missed that”
could be used for a single character literal - oops! Thanks for saving a byte.
$endgroup$
– Nick Kennedy
7 hours ago
add a comment |
$begingroup$
Jelly, 108 99 bytes
“¢¥Þ‘Ṭ+þ³ḤN+“¢¤€‘¤ṬḤ;Ø0¤×3R¤¦€³+0x39¤µ‘03³?‘;20¤¦€1,-2¦;565DWx“¢%¢‘¤;UṚ$ị“|-+TO= ””F21¦€³Ḥ_⁵¤¦UṚƭ⁴¡
Try it online!
I’m sure this can be better golfed.
Dyadic link with left argument 0 or 1 for singles/doubles and right argument 0,1,2,3 for different serve quadrants. Returns a list of strings
Thanks to @KevinCruijssen for saving a byte!
$endgroup$
Jelly, 108 99 bytes
“¢¥Þ‘Ṭ+þ³ḤN+“¢¤€‘¤ṬḤ;Ø0¤×3R¤¦€³+0x39¤µ‘03³?‘;20¤¦€1,-2¦;565DWx“¢%¢‘¤;UṚ$ị“|-+TO= ””F21¦€³Ḥ_⁵¤¦UṚƭ⁴¡
Try it online!
I’m sure this can be better golfed.
Dyadic link with left argument 0 or 1 for singles/doubles and right argument 0,1,2,3 for different serve quadrants. Returns a list of strings
Thanks to @KevinCruijssen for saving a byte!
edited 7 hours ago
answered Apr 1 at 22:22
Nick KennedyNick Kennedy
1,50649
1,50649
$begingroup$
I don't know Jelly, so I probably say something stupid here, but with“|-+TO= ”“F”
, can't the“F”
be golfed to another type of string for single characters? In 05AB1E for example, there are builtins for strings of size 1 ('
), 2 („
), or 3 (…
), so it could be'F
. Don't know if Jelly has something similar, or if you have another reason for it to be“|-+TO= ”“F”
?
$endgroup$
– Kevin Cruijssen
Apr 2 at 8:51
1
$begingroup$
@KevinCruijssen Thanks, and nice challenge. I don’t think so. There are two character literals (with ⁾), but not one. I could use a number 7 and add the F to the lookup, but it’s the same number of characters because of the need to follow the 7 with a 21 which therefore needs a space to separate the two.
$endgroup$
– Nick Kennedy
Apr 2 at 13:13
$begingroup$
Well, as I said, I don't know Jelly. Thought it might have some builtins for 1 or 2-character strings as well, but if you say not I believe you. :)
$endgroup$
– Kevin Cruijssen
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I’m happy for someone else to jump in - still learning!
$endgroup$
– Nick Kennedy
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I completely missed that”
could be used for a single character literal - oops! Thanks for saving a byte.
$endgroup$
– Nick Kennedy
7 hours ago
add a comment |
$begingroup$
I don't know Jelly, so I probably say something stupid here, but with“|-+TO= ”“F”
, can't the“F”
be golfed to another type of string for single characters? In 05AB1E for example, there are builtins for strings of size 1 ('
), 2 („
), or 3 (…
), so it could be'F
. Don't know if Jelly has something similar, or if you have another reason for it to be“|-+TO= ”“F”
?
$endgroup$
– Kevin Cruijssen
Apr 2 at 8:51
1
$begingroup$
@KevinCruijssen Thanks, and nice challenge. I don’t think so. There are two character literals (with ⁾), but not one. I could use a number 7 and add the F to the lookup, but it’s the same number of characters because of the need to follow the 7 with a 21 which therefore needs a space to separate the two.
$endgroup$
– Nick Kennedy
Apr 2 at 13:13
$begingroup$
Well, as I said, I don't know Jelly. Thought it might have some builtins for 1 or 2-character strings as well, but if you say not I believe you. :)
$endgroup$
– Kevin Cruijssen
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I’m happy for someone else to jump in - still learning!
$endgroup$
– Nick Kennedy
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I completely missed that”
could be used for a single character literal - oops! Thanks for saving a byte.
$endgroup$
– Nick Kennedy
7 hours ago
$begingroup$
I don't know Jelly, so I probably say something stupid here, but with
“|-+TO= ”“F”
, can't the “F”
be golfed to another type of string for single characters? In 05AB1E for example, there are builtins for strings of size 1 ('
), 2 („
), or 3 (…
), so it could be 'F
. Don't know if Jelly has something similar, or if you have another reason for it to be “|-+TO= ”“F”
?$endgroup$
– Kevin Cruijssen
Apr 2 at 8:51
$begingroup$
I don't know Jelly, so I probably say something stupid here, but with
“|-+TO= ”“F”
, can't the “F”
be golfed to another type of string for single characters? In 05AB1E for example, there are builtins for strings of size 1 ('
), 2 („
), or 3 (…
), so it could be 'F
. Don't know if Jelly has something similar, or if you have another reason for it to be “|-+TO= ”“F”
?$endgroup$
– Kevin Cruijssen
Apr 2 at 8:51
1
1
$begingroup$
@KevinCruijssen Thanks, and nice challenge. I don’t think so. There are two character literals (with ⁾), but not one. I could use a number 7 and add the F to the lookup, but it’s the same number of characters because of the need to follow the 7 with a 21 which therefore needs a space to separate the two.
$endgroup$
– Nick Kennedy
Apr 2 at 13:13
$begingroup$
@KevinCruijssen Thanks, and nice challenge. I don’t think so. There are two character literals (with ⁾), but not one. I could use a number 7 and add the F to the lookup, but it’s the same number of characters because of the need to follow the 7 with a 21 which therefore needs a space to separate the two.
$endgroup$
– Nick Kennedy
Apr 2 at 13:13
$begingroup$
Well, as I said, I don't know Jelly. Thought it might have some builtins for 1 or 2-character strings as well, but if you say not I believe you. :)
$endgroup$
– Kevin Cruijssen
Apr 2 at 13:15
$begingroup$
Well, as I said, I don't know Jelly. Thought it might have some builtins for 1 or 2-character strings as well, but if you say not I believe you. :)
$endgroup$
– Kevin Cruijssen
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I’m happy for someone else to jump in - still learning!
$endgroup$
– Nick Kennedy
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I’m happy for someone else to jump in - still learning!
$endgroup$
– Nick Kennedy
Apr 2 at 13:15
$begingroup$
@KevinCruijssen I completely missed that
”
could be used for a single character literal - oops! Thanks for saving a byte.$endgroup$
– Nick Kennedy
7 hours ago
$begingroup$
@KevinCruijssen I completely missed that
”
could be used for a single character literal - oops! Thanks for saving a byte.$endgroup$
– Nick Kennedy
7 hours ago
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182496%2frelevant-part-for-a-badminton-serve%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Ah, badminton. The one game I’ve always wanted to play but never got around to because forgot/couldn’t find players to play with
$endgroup$
– Quintec
Apr 1 at 11:59
$begingroup$
@Quintec Feel free to come visit our club in The Netherlands for a free evening ;p
$endgroup$
– Kevin Cruijssen
Apr 1 at 12:20
1
$begingroup$
Deal, if you pay for my plane ticket and hotel? :)
$endgroup$
– Quintec
Apr 1 at 13:13
1
$begingroup$
@Quintec If you win, I'll pay the flight ticket back, haha xD
$endgroup$
– Kevin Cruijssen
Apr 1 at 13:21
1
$begingroup$
@MagicOctopusUrn Yes, there are some professional badminton players from The Netherlands. Not sure what rank they have on the world list tbh, I don't watch badminton that often (and usually it's only 5 minutes on the sport news if mentioned at all anyway.. all other time is wasted with soccer). And no, as top player you might barely make an income I think. Definitely not millions.
$endgroup$
– Kevin Cruijssen
Apr 2 at 6:59