# Positions on the Pickleball Court

My doubles pickleball group often has five people. Four are playing and one is awaiting the next game. We can represent the state of the game with a string of five characters like abCde. This indicates that a and b are playing against c and d with c serving. We want to write a routine that gives the possible positions after the next rally is complete. The examples below will assume we start with this configuration.

For those unfamiliar with the game, two players are paired to play against the other two. One of the players serves to put the ball in play. A rally consists of play until one side fails to hit the ball back legally, at which point it is won by the side that did not fail. Only the serving side scores points for winning a rally. The receiving side only moves the serve along by winning a rally.

There are four possible outcomes of a rally.

1. The serving side wins the rally but does not win the game. The players on the serving side change places and the same player serves, so we go to abdCe.

2. The serving side wins the rally and thereby wins the game. The players rotate one position right and the serve goes to the first position, so we go to Eabcd

3. The receiving side wins the rally, but the partner of the server has not served yet. The players stay in position and the serve goes to the partner, so we go to abcDe

4. The receiving side wins the rally and the partner of the server has served. The players stay in position and the serve goes to the first player of the other side, the one in first or third position. Here we go to Abcde

Your task is to write a routine that takes a configuration at the start of a rally and returns or prints the four possible configurations at the end of the rally in the order of the possibilities above. A configuration has the five characters in any order with the server any of the first four. This is code golf, so the shortest solution wins. You can use other characters and other ways of indicating the server if you wish, like digits and making the server negative or adding $5$ to the server or putting an asterisk after the server. There needs to be a clear break between the four possibilities, like a space, a newline, or separate elements of a list. You can take your input in any convenient way, as a string or array for example. The characters used should be the same on input and output.

Test cases-input first column, output the remaining four

Abcde bAcde Eabcd aBcde abCde

caBed caeBd Dcabe cabEd Cabed

dBace Bdace Edbac Dbace dbAce


• Can input be integers, with capital specified by negative or by adding 32, etc? Nov 4 at 6:37
• I don't see the "win the game" outcome for the second test case.
– Neil
Nov 4 at 11:25
• @Neil: it was incorrect. Fixed. Thanks Nov 4 at 13:22
• @Jonah: yes, that would be fine. $5$ was just an example that leaves you in single digits Nov 4 at 13:22
• Do they have to be in the order specified? Nov 4 at 22:47

# Jelly, 40 bytes

AN⁸NM’ỊḤ‘¤¦,@ṙ-AN1¦Ɗż@s2WU,NƊṠE$?€ŒpF€ƲẎ  Try it online! A monadic link taking a list of integers and returning a list of lists of integers in the order specified. Servers are indicated by negative numbers. If the order of results could be more flexible, I can save three bytes. ## Explanation AN⁸NM’ỊḤ‘¤¦,@ṙ-AN1¦Ɗż@s2WU,NƊṠE$?€ŒpF€ƲẎ­⁡​‎‎⁪⁡⁪⁠⁪⁡⁪‏‏​⁡⁠⁡‌⁢​‎‎⁪⁡⁪⁠⁪⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁣⁪‏‏​⁡⁠⁡‌⁣​‎‎⁪⁡⁪⁠⁪⁤⁪‏⁠⁪⁪⁠⁪⁪‏​⁡⁠⁡‌⁤​‎‎⁪⁡⁪⁠⁪⁢⁡⁪‏‏​⁡⁠⁡‌⁢⁡​‎‎⁪⁡⁪⁠⁪⁢⁢⁪‏‏​⁡⁠⁡‌⁢⁢​‎‎⁪⁡⁪⁠⁪⁢⁣⁪‏‏​⁡⁠⁡‌⁢⁣​‎‎⁪⁡⁪⁠⁪⁢⁤⁪‏‏​⁡⁠⁡‌⁢⁤​‎‎⁪⁡⁪⁠⁪⁣⁡⁪‏‏​⁡⁠⁡‌⁣⁡​‎‎⁪⁡⁪⁠⁪⁣⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁤⁪‏‏​⁡⁠⁡‌⁣⁢​‎‎⁪⁡⁪⁠⁪⁤⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁣⁪‏‏​⁡⁠⁡‌⁣⁣​‎‎⁪⁡⁪⁠⁪⁤⁤⁪‏‏​⁡⁠⁡‌⁣⁤​‎‎⁪⁡⁪⁠⁪⁢⁡⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁣⁪‏‏​⁡⁠⁡‌⁤⁡​‎‎⁪⁡⁪⁠⁪⁢⁢⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁢⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁢⁣⁪‏‏​⁡⁠⁡‌⁤⁢​‎‎⁪⁡⁪⁠⁪⁢⁢⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁢⁤⁪‏‏​⁡⁠⁡‌⁤⁣​‎⁪⁪⁠‎⁪⁡⁪⁠⁪⁢⁤⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁤⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁤⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁡⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁡⁢⁪‏‏​⁡⁠⁡‌⁤⁤​‎‎⁪⁡⁪⁠⁪⁢⁣⁡⁪‏‏​⁡⁠⁡‌⁢⁡⁡​‎‎⁪⁡⁪⁠⁪⁢⁣⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁣⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁣⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁤⁡⁪‏‏​⁡⁠⁡‌⁢⁡⁢​‎‎⁪⁡⁪⁠⁪⁣⁡⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁡⁤⁪‏‏​⁡⁠⁡‌⁢⁡⁣​‎‎⁪⁡⁪⁠⁪⁣⁢⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁢⁢⁪‏‏​⁡⁠⁡‌⁢⁡⁤​‎‎⁪⁡⁪⁠⁪⁣⁢⁤⁪‏‏​⁡⁠⁡‌­
A                                         # ‎⁡Absolute
N⁸      ¤¦                               # ‎⁢Negate at the index given by running the following on the original argument:
N                                      # ‎⁣- Negate
M                                     # ‎⁤- Indices (here single index) of max (will be the index of the server)
’                                    # ‎⁢⁡- Decrement by 1
Ị                                   # ‎⁢⁢- <= 1
Ḥ                                  # ‎⁢⁣- Double
‘                                 # ‎⁢⁤- Increment by 1
,@      Ɗ                      # ‎⁣⁡Pair in reverse order with the result of running the following on the original argument:
ṙ-                           # ‎⁣⁢- Rotate once to the right
A                          # ‎⁣⁣- Absolute
N1¦                       # ‎⁣⁤- Negate first index
ż@                Ʋ   # ‎⁤⁡Zip in reverse order with the result of applying the following to the original argument:
s2                  # ‎⁤⁢- Split into lists of length 2
ṠE\$?€        # ‎⁤⁣- For each of these sublists, if the signs are equal:
W                 # ‎⁤⁤  - Then wrap in a further list
U,NƊ             # ‎⁢⁡⁡  - Else pair the reversed sublist with the negated sublist
Œp      # ‎⁢⁡⁢- Cartesian product
F€    # ‎⁢⁡⁣- Flatten each
Ẏ  # ‎⁢⁡⁤Join outermost lists
💎


Created with the help of Luminespire.

# APL+WIN, 93 85 bytes

Prompts for players as integers 1 to 5 with the server shown as negative:

m←⎕⋄m⋄t←⊂[2]2 2⍴m⋄m←4↓m⋄(∊(+/¨0>¨t)⌽¨t),m⋄(-m),∊s←|t⋄(∊t×2/¨u←×/¨×t),m⋄(∊s×(⌽u),¨1),m


Try it online! Thanks to Dyalog Classic

# Charcoal, 57 bytes

⟦⭆⪪θ²⎇⊙ι№αλ⮌ιι⁺↥§θ⁴↧…θ⁴⭆⪪θ²⭆ι⎇№α§ι¬μ↥λ↧λ⭆θ⎇⁼κ⊗⊙…θ²№αλ↥ι↧ι


Try it online! Link is to verbose version of code. Explanation:

⟦


Print each of the following expressions on their own line.

⭆⪪θ²⎇⊙ι№αλ⮌ιι


Split the input into pairs of letters and reverse the pair which contains an uppercase letter. (The last letter is always unaffected; even if it was in upper case, reversing it would have no effect.)

⁺↥§θ⁴↧…θ⁴


Uppercase the last letter of the input and concatenate that with the lowercased first four letters.

⭆⪪θ²⭆ι⎇№α§ι¬μ↥λ↧λ


Split the input into pairs of letters and set each letter's case to that of the other letter in the pair. (The last letter becomes set to its case, which has no effect.)

⭆θ⎇⁼κ⊗⊙…θ²№αλ↥ι↧ι


If one of the first two letters is in uppercase then uppercase only the third letter otherwise uppercase only the first letter.

# C (GCC), 238 226 bytes

#define Q),q(
q(x){putchar(x+48);}f(a,b,c,d,e,z){z=(a|b)&1;z?q(b Q a Q c Q d):(q(a Q b Q d Q c)Q e Q'/'Q e|1 Q~1&a Q~1&b Q~1&c Q~1&d Q'/'Q a^z Q b^z Q!z^c Q!z^d Q e Q 47);z?q(a&~1 Q~1&b Q c|1 Q d):(q(a|1 Q b Q~1&c Q~1&d)Q e);}


Attempt This Online!

While it looks daunting, the way this works is actually simple. f takes 5 players as parameters, where odd numbers denote the server (aka least-significant bit). That is, numbers 0 and 1 are the same player, 2 and 3, etc.

The function q outputs a digit. z tests whether one of the first players is the server and is used later for some conditions. The random-looking 47 is the separator between the outcomes, as 47+48=95, so an underscore. Any number from 10 to 99 or even -1 to -9 would work. Sadly, one digit is not possible, as all numbers from 0 through 9 are possible players.

The outputs are constructed using bit manipulation to set, remove or flip the LSB.

-12 bytes thanks to ceilingcat