The easiest way is just to simulate the game lots of times. The R code below simulates a single game.
nplayers = 4
#Create an empty data frame to keep track
#of card number, suit and if it's magic
empty.hand = data.frame(number = numeric(52),
suit = numeric(52),
magic = numeric(52))
#A list of players who are in the game
players =list()
for(i in 1:nplayers)
players[[i]] = empty.hand
#Simulate shuffling the deck
deck = empty.hand
deck$number = rep(1:13, 4)
deck$suit = as.character(rep(c("H", "C", "S", "D"), each=13))
deck$magic = rep(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0), each=4)
deck = deck[sample(1:52, 52),]
#Deal out five cards per person
for(i in 1:length(players)){
r = (5*i-4):(5*i)
players[[i]][r,] = deck[r,]
}
#Play the game
i = 5*length(players)+1
current = deck[i,]
while(i < 53){
for(j in 1:length(players)){
playersdeck = players[[j]]
#Need to test for magic and suit also - left as an exercise!
if(is.element(current$number, playersdeck$number)){
#Update current card
current = playersdeck[match(current$number,
playersdeck$number),]
#Remove card from players deck
playersdeck[match(current$number, playersdeck$number),] = c(0,
0, 0)
} else {
#Add card to players deck
playersdeck[i,] = deck[i,]
i = i + 1
}
players[[j]] = playersdeck
#Has someone won or have we run out of card
if(sum(playersdeck$number) == 0 | i > 52){
i = 53
break
}
}
}
#How many cards are left for each player
for(i in 1:length(players))
{
cat(sum(players[[i]]$number !=0), "\n")
}
Some comments
- You will need to add a couple of lines for magic cards and suits, but data structure is already there. I presume you didn't want a complete solution? ;)
- To estimate the average game length, just place the above code in a function and call lots of times.
- Rather than dynamically increasing a vector when a player gets a card, I find it easier just to create a sparse data frame that is more than sufficient. In this case, each player has a data frame with 52 rows, which they will never fill (unless it's a 1 player game).
- There is a small element of strategy with this game. What should you do if you can play more than one card. For example, if 7H comes up, and you have in your hand 7S, 8H and the JC. All three of these cards are "playable".
In short, the probability of a 7-card straight when drawing 7 random cards from a standard deck of 52 is $0.000979$.
To calculate this value, we note that all 7-card hands are equally likely, of which there are ${52 \choose 7} = 133,784,560$ possibilities.
Next, we compute the number of 7-card straights. Ignoring suit, we note that there are $8$ possible straights (starting with {A, 2, 3, 4, 5, 6, 7} through {8, 9, 10, J, Q, K, A}). For each card in the straight, there are 4 possibilities for the suit, such that there are $4^7 = 16384$ ways to assign the suits to the 7 cards. However, $4$ of these suit assignments yield straight flushes (all clubs, all diamonds, etc.), so the actual number of suit assignments that can yield a straight (but not a straight flush) is $16384 - 4 = 16380$.
Putting all this together, there are $8 \times 16380 = 131,040$ possible 7-card straights out of $133,784,560$ possible 7-card hands, yielding a probability of $\approx 0.000979$.
Best Answer
The answer is a tiny number, but large enough to suggest someone has at sometime been dealt a suit in the US. This post shows how to find that chance (with a sequence of three simple calculations), provides an interpretation, and concludes by showing how to compute it accurately.
Let's begin with a small generalization, because it uncovers the essence of the problem. Let a "suit" consist of $k\ge 1$ cards. A "deck" is the union of $m\ge 1$ distinct suits. In the question, $k=13$ and $m=4$. To model a deal, suppose the deck is randomly shuffled and partitioned into $m$ groups of $k$ contiguous cards in the shuffle. Each of these groups is a "hand".
First let's find the chance that one pre-specified player is dealt a suit. There are $$\binom{mk}{k} = \frac{(mk)(mk-1)\cdots((m-1)k+1)}{(k)(k-1)\cdots(1)}$$ possible hands, all of them equally likely, and $m$ of them are suits. This chance therefore is
$$p^{(1)}(m,k) = \frac{m}{\binom{mk}{k}}.\tag{1}$$
If this is what the question was asking, we are done. However, the more likely interpretation is that it asks for the chance that one or more of the hands is a suit.
To do this, proceed to find the chance that two pre-designated players are dealt suits. Conditional on the first player being dealt a suit (the chance given by $(1)$), there remain $m-1$ suits. Result $(1)$ applies with $m$ replaced by $m-1$ to give the conditional probability. These two values multiply to give the joint probability
$$p^{(2)}(m,k) = p^{(1)}(m,k)p^{(1)}(m-1,k).$$
Continuing this reasoning inductively gives the chance that $s\ge 1$ pre-designated players each are dealt suits,
$$p^{(s)}(m,k) = \prod_{i=0}^{s-1} p^{(1)}(m-i,k).\tag{2}$$
The Principle of Inclusion-Exclusion ("PIE") supplies the chance that one or more players (not designated in advance) are dealt suits; it is
$$p(m,k) = \sum_{s=1}^m (-1)^{s-1} \binom{m}{s} p^{(s)}(m,k).\tag{3}$$
In particular, $$\eqalign{ p(4,13) &= \frac{(3181)(233437)(25281233)}{(2^6)(3)(5^4)(7^4)(17^3)(19^2)(23^2)(29)(31)(37)(41)(43)(47)} \\ &=\frac{18772910672458601}{745065802298455456100520000}\\ &\approx 2.519631234522642\times 10^{-11}. }$$
The small primes in the denominator were expected: they cannot exceed $mk=52$. The large primes in the numerator strongly suggest there exists no general closed form formula for $p(m,k)$.
What does this answer mean?
Wikipedia traces the modern version of Bridge to 1904, states that it used to be more popular in the US, and reports there are around 25 million players today in the US. Although it's difficult to know exactly what it means to be a Bridge player, we might expect each one on average to play between a few hands and a few hundred hands annually, with each hand involving four players. (In Duplicate Bridge some deals are played multiple times, but let's ignore that complication and just absorb it into the "few to a few hundred" estimate.) The expected number of Bridge deals annually in the US in which a suit is dealt therefore is on the order of ten to a hundred times the product
$$p(4,13) \times 25 \times 10^6 \approx \frac{1}{1588}.$$
Accounting for the $110$ or so years that have transpired since 1904, we might multiply this expectation by another two orders of magnitude. The result is somewhere between $1/10$ and $10$. Although $p(4,13)$ might seem "impossibly small," it is not negligible: depending on the assumptions about how active Bridge players have been, it's somewhere between plausible and highly likely a suit has already been dealt in the US.
Many people have reported such hands. The obvious explanation is that some (many?) decks are not randomly shuffled or dealt. See Peter Rowlett on Four Perfect Hands or Science News on Thirteen Spades.
Computing notes
Computing the answer is as straightforward and simple as it looks in formulas $(1)$, $(2)$, and $(3)$: see the
R
example below. When applying PIE it's usually best to avoid large values of $m$ due to the alternating addition and subtraction in the final formula: round-off error can accumulate rapidly when some individual terms in the sum are much greater in size than the result. This situation is nicer. Since in general the first term--based on the chance of just one particular player getting a suit--dominates the rest, this code performs the sum in reverse order to avoid that roundoff error.The result is correct to the full precision inherent in IEEE floating point arithmetic.
References
Gridgeman, N. T. "The Mystery of the Missing Deal." Amer. Stat. 18, 15-16, Feb. 1964.
Mosteller, F. "Perfect Bridge Hand." Problem 8 in Fifty Challenging Problems in Probability with Solutions. New York: Dover, pp. 2 and 22-24, 1987.
Wolfram Mathworld quotes the same rational value for $p(4,13)$. Its references are Mosteller and Gridgeman.