How this calculation works
Count successful completions of partial classical parking preferences and return one arrival-by-arrival parking witness.
A car with preference a parks in the first free spot j≥a; count all wildcard choices for which every car parks.A worked example
Four wildcard preferences have 5³=125 successful completions. One witness is 1,1,1,1, parking the four arriving cars in spots 1,2,3,4.
Good to know
1–12 cars and equally many spots numbered 1…n. Each preference is 1…n or ?/*; exact BigInt mask dynamic programming. Cars scan only right, arrive in entered order and never move afterward.
Reference: SageMath parking functions: definition and parking permutation (opens in a new tab) ↗
Sequential parking is not random box allocation
There are n cars and n parking spots in a one-way line. Each arriving car first tries its preferred spot, then scans rightward until it finds a free one. If no spot at or beyond its preference is free, that car fails and the preference list is not a parking function.
Earlier cars can therefore affect later cars even when their original preferences differ. A successful list does not require distinct preferences, and several cars can prefer spot 1 and still all park. This is different from independently placing balls into boxes or requiring each car to use exactly its first-choice spot.
Compare this with the Occupied boxes probability calculator for random allocations. Count preference completions that let sequential cars park by scanning right from their preferred spot. Independent random allocation of balls to boxes neither scans for the next empty spot nor encodes order-sensitive failures.
Use wildcards to ask a completion question
Enter one preference per car in arrival order. An integer fixes that car’s first-choice spot. A question mark or asterisk allows any preference from 1 through n independently for that car. The calculator counts how many complete preference lists compatible with those choices let every car park successfully.
Wildcards represent unknown or freely chosen preferences, not probabilities by themselves. If every available preference is considered equally likely and independent, the count can later be divided by n raised to the number of wildcards to obtain a probability under that additional model. The primary output remains an exact count of successful lists.
Track occupied spots with dynamic programming
After k cars have parked, the occupied set determines every future parking possibility. The identities of the parked cars are irrelevant because cars never move again. A bit mask records that set, and its number of occupied positions also determines which car arrives next in the fixed input order.
For each permitted preference of the next car, the algorithm finds the first free spot to its right and recurses on the updated mask. Different preference choices that reach the same occupied mask are still counted separately. Memoization shares their future count without mistakenly merging the distinct completed preference lists that led there.
Read the four-wildcard example
With four cars and four spots, allowing every preference independently gives 4⁴=256 possible complete lists. Exactly (4+1)^(4−1)=125 are successful classical parking functions. The calculator obtains the same result by the occupied-mask recurrence rather than relying only on that closed-form total.
One successful completion is 1,1,1,1. The first car takes spot 1, and each following car scans past occupied spots to take the next free one. Their displacements are 0,1,2,3, summing to 6. This witness proves success of one completion, while the dynamic program counts all 125 possibilities.
Inspect success and failure witnesses
When the completion count is positive, the output includes one complete preference list and the final spot and displacement of every car. Replaying those arrivals verifies that each chosen spot is free and is the first available spot at or to the right of that car’s entered preference.
If all preferences are fixed and the list fails, the calculator identifies the first failing car and its preference. For a partial list with zero successful completions, there need not be one common failing arrival shared by every completion. A zero count is therefore reported without inventing a universal failing-car explanation for all wildcard assignments.
Use classical characterizations carefully
For a fully specified list, sorting its preferences as b₁≤…≤b_n gives a classical parking-function test: the list succeeds exactly when b_i≤i for every i. The simulation still uses the original arrival order to determine which named car occupies which spot and how far each car moves.
Thus success of a complete preference multiset is invariant under reordering its cars, but individual placements and displacements generally are not. The calculator preserves arrival order in its witness. It does not replace the original list by the sorted one and then claim that the resulting car-by-car assignments describe the original sequence.
Know the count and model limits
The twelve-car limit gives at most 4096 occupied masks, while exact counts are stored as BigInt strings. This avoids rounding large combinatorial totals into nearby floating-point integers. The number of dynamic states describes memoization work and is not the number of successful completions.
Only classical one-way parking on a line with as many spots as cars is modeled. Circular parking, backward search, reserved spaces and alternative collision rules have different counts. Keep those variants separate when comparing formulas, and do not infer a physical congestion forecast from this deterministic combinatorial process without a corresponding model of real arrivals and preferences.
A few questions, answered
Can several cars prefer the same spot?
Yes. Later cars scan to the right for the next free spot, so repeated preferences can still succeed.
Does a wildcard mean a random preference?
It permits every preference 1…n. A probability interpretation additionally requires a specified distribution over those choices.
Why is the count returned as a string?
It is an exact BigInt combinatorial count, which avoids floating-point integer rounding.
Does sorting the list preserve each car’s final spot?
No. Sorting gives a success criterion, but the original arrival order determines individual parking assignments and displacements.