Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Determine whether a list of positive integers is a valid parking function
Test if a list is a valid parking function:
| In[1]:= |
| Out[2]= |
The following list is not a valid parking function because the second car parks at the third spot so there is no valid spot for the last car:
| In[3]:= |
| Out[4]= |
Enumerate all parking functions with length three:
| In[5]:= |
| Out[6]= |
Verify the result with the length formula:
| In[7]:= |
| Out[7]= |
Show which tuples are not valid parking functions:
| In[8]:= |
| Out[8]= |
The code below takes a parking function and returns the actual order in which the cars will park:
| In[9]:= | ![]() |
Give preferred parking spots for cars labelled from 1 to 7:
| In[10]:= |
Calculate where the cars actually park, starting with car number one in the sixth spot:
| In[11]:= |
| Out[11]= |
Find the permutation after all cars have parked (spot 6 is taken by car 1, spot 1 by car 2, etc.):
| In[12]:= |
| Out[12]= |
The jump list shows that car 1 through 4 parked in their preferred spots, car 5 had to jump one space further, car 6 had to jump 3 spots and car 7 had to jump two spots:
| In[13]:= |
| Out[13]= |
The lucky cars are the ones parked at their preferred spot, which is the position of zeros in the jump list above:
| In[14]:= |
| Out[14]= |
Test if the following list is a valid parking function:
| In[15]:= | ![]() |
| Out[16]= |
All permutations of the input are valid as well:
| In[17]:= |
| Out[17]= |
The input must be a list of nonnegative integers. Otherwise the function returns unevaluated:
| In[18]:= |
| Out[18]= |
| In[19]:= |
| Out[19]= |
This work is licensed under a Creative Commons Attribution 4.0 International License