Combinatorics of cardgame hand evaluation for runs, with wildcards and duplicates
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
In the fascinating world of card games, hand evaluation is a pivotal aspect, especially when considering runs. A run is a sequence of consecutive cards, typically of the same suit, and is of fundamental importance in games like Rummy. Adding complexity to the evaluation are wildcards and duplicate cards. The combinatorics involved in such systems can be intricate, yet they offer a compelling exploration into the realm of probability and discrete mathematics. In this article, we shall undertake a detailed examination of combinatorics in evaluating card game hands involving runs, focusing on scenarios with wildcards and duplicate cards.
Understanding Runs in Card Games
A run, in its simplest form, consists of consecutive cards that follow one another in a sequence. For example, in a standard deck, `5-6-7` is a run. When evaluating runs:
• Conventional Runs: These adhere strictly to consecutive order without any substitutes. • Wildcards: These cards can be substituted as any card. For instance, considering a wildcard `W`, `5-W-7` can represent the run `5-6-7`. • Duplicates: These are multiple copies of the same card, which can influence the formation of multiple potential runs or emphasize a single run's probability.
Combinatorial Evaluation: Basic Principles
Notation
- S: Denotes the number of suits.
- R: Denotes the number of ranks.
- W: The number of wildcards available.
- D: The number of duplicate cards allowed per rank per suit.
- n: The length of the run required.
A standard deck, without any wildcards or duplicates, comprises 52 cards (4 suits, 13 ranks per suit).
Basic Combinatorics
For ordinary runs without wildcards or duplicates: • The number of possible 3-card runs in a single suit is calculated through combinations of the ranks. For instance, without duplicates, using gives the starting rank position, allowing us to count runs like `A-2-3` through `Q-K-A`.
Wildcards in Runs
Wildcards add complexity by providing flexibility in forming runs. Consider a sequence `5-W-7`:
- The wildcard can be `6`, thus completing a valid run.
- In terms of combinatorial possibilities, each wildcard addition exponentially increases the number of potential valid sequences.
For analysis, the number of possible runs using `W` wildcards can be calculated as: \\sum\_{k=0}^{W} \binom{n}{k} \cdot \binom{R-k}{n-k}\
Where selects positions in the sequence that the wildcards will occupy.
Duplicates in Runs
Duplicate cards also play a significant role in combinatorial evaluation. Duplicates allow multiple cards of the same rank, such as in Poker scenarios where a pair contributes to a full house.
• Considering duplicates, evaluate the number of potential sequences: • Calculate using , which accounts for each possible sequence of ranks multiplied by the `D` duplicates for each rank.
Combining Wildcards and Duplicates
Combining wildcards and duplicates involves a synthesis of the above principles. The presence of both elements creates an overlapping of permutation possibilities.
• The total number of unique sequences is addressed by adding constraints to consider both factors simultaneously.
Example Analysis
Suppose you are evaluating a potential run in a modified Rummy deck: • 2 Wildcards (`W = 2`) • Maximum duplicates per rank and suit (`D = 2`) • Focus on 4-card runs (`n = 4`)
Calculate potential valid runs:
- Without any wildcards or duplicates, possible runs: distinct runs per suit.
- Considering wildcards: With 2 wildcards, capable of filling any position, additional runs generated as .
- Considering duplicates: Each existing permutation has `2^4 = 16` variations due to duplicates.
Combining these calculations delivers a comprehensive look at all potential hand configurations.
Comprehensive Summary Table
| Aspect | Calculation | Description |
| Base Runs (No Mods) | Determines base sequences per suit | |
| Wildcards Influence | Adjust sequences considering flexible positions | |
| Duplicates Influence | Accounts for multiple identical cards per rank | |
| Combination Complexity | Factors both wildcards and duplicates | Overlap of combinatorial possibilities |
| Total Hand Evaluation |
Exploring the combinatorics of card games with runs, wildcards, and duplicates showcases the intricate interactivities and rich problem space within card-based combinatorics. Such an analysis is not only applicable to game design but also extends to probability theory, enriching understanding in statistics and beyond.
Related reading
- Combine smaller rectangles into larger ones
- Combined area of overlapping circles
- Compare two numbers for likeness
- Complete Weighted Graph and Hamiltonian Tour
- Complexity when generating all combinations
- Compute rand7 using rand5
- Compute the area of intersection between a circle and a triangle?
- Compute the Cross Section of a Cube

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.