One for the Math Geeks

After the world’s most intense game of Spider SOLITAIRE played by Spider GM, two International Masters and three coloured blobs from Among Us, followed by some rather detailed post-mortem analysis I think now is a good time for some light relief with some rot13(zngurzngvpny znfgheongvba). More specifically, we answer the following question: if cards are dealt one at a time from a perfectly shuffled deck, how long do we have to wait until a full suit appears?

The relevance to Spider Solitaire players should be pretty clear: we have absolutely no control over what cards turns up. If, for example, there are no Queens in the first 20 cards then the chances of the next turnover being a Queen are exactly 8 in 84 – no amount of skilled or unskilled play can fight the basic laws of probability. All you can do is hope to mitigate the effects of not getting any Queens in the first 20 cards with skilful play. Similar considerations apply if you’re in the middle-game desperately waiting on the Three of Diamonds to complete a full suit.

If you insist on shifting the odds, we can commit the cardinal sin of Spider Solitaire by using rot13(haqb). Alternatively, we can somehow fail to obtain any turnovers in the tableau for the remainder of the game – in either case, the mere thought is too horrible to contemplate.

There is one minor complication: when dealing from the stock 10 cards appear simultaneously (which I mentioned more than once during the post-mortem of the Among-Us game). Here we will assume they appear sequentially. In the example below, a row of 10 cards has just been dealt. There are 61 cards visible, and by the time the Three of Diamonds is dealt we see every card in Diamonds. In other words, we needed 60 cards to obtain a full suit.

Clearly, the minimum number of cards required is 13 and the maximum is 96 (if we get e.g. no Kings until the last eight cards). During the Among Us game I thought we were fairly lucky to see a full suit after 60 cards. From experience I would expect we need more cards visible before the chances of seeing a full suit are 50%. However, I never bothered to quantify this. Fortunately, it is relatively straightforward to run a computer simulation. We might simulate X hands and find e.g. we need on average Y cards instead of 60 before there is an even chance of finding a complete suit. If Y cards corresponds to the Zth percentile then we would know where we stand in terms of how lucky we were.

In this case, I ran 5000 iterations and found 60 or lower cards were needed to achieve a complete suit 1176 times. This corresponds to the 22nd or 23rd percentile. The mean and median is closer to 66.5 and 67.0 respectively.

As I suspected, we did get lucky with the Diamond suit, but nowhere near enough to justify improvising a rap song with the phrase “statistically significant” appearing once every ten seconds. To put this in Dungeons & Dragons terms, if this game of Spider Solitaire were a character, then we would have rolled better-than-average initial stats for complete-suits, but nobody in their right mind would accuse the dice of being rigged. Presumably we would have lousy initial stats for other abilities such as turnovers or shortages of particular ranks etc (I did have some misgivings about our winning chances during this hand therefore something had to be lousy), but unfortunately there is only so far one can go with the Dungeons & Dragons analogy.

Without the ability to remove Diamonds, I expect we would have been in more trouble than Ian Nepomniachtchi’s Bishop getting harassed by both Black rooks after capturing a poisoned pawn in Game 9 of the World Chess Championship since no other suit is close to completion. I’m not sure what’s the best way to test this conjecture via simulation, so if you have any clever ideas, please leave a comment 😊

2 thoughts on “One for the Math Geeks

  1. Well, if you wanted a buddy in mathematical speculation, you’ve got one here!

    I would think that the point at which you first get a full suit is a rather coarse measure of luck. What does a complete suit get you? Removing one king. And perhaps losing the ability of that nearly complete suit to serve as “lubricant” in sorting out other columns. But getting a complete suit is surely correlated with various other kinds of luck too.

    I’ve already introduced now and then my idea of “bumpiness”. It starts with sorting all the cards you’ve seen by rank, and then looking at the counts of adjacent ranks. The more they differ, the more bumpy your cards are, and the worse your situation. It captures why
    A 2 3 4 5 6 7 8 9 t is very nice distribution (bumpiness 0) and
    A A 3 3 5 5 7 7 9 9 is a very bad one (bumpiness 16). So if you’ve seen X cards and a bumpiness of Y, is that good luck or not? I have had for years a computer simulation that will deal the cards 100,000 times, take the first X of each deal, and compute the bumpiness. So then we can see if our Y is better or worse luck than average, and by how much.

    Now, in the game posts/blockchains, I get confused figuring out just which set of cards corresponds to what point, like, “where do we see situation at end of round 3?” But I do know there is a score at the top of each diagram, which should allow people who can navigate better to find points they want evaluated. I picked four of them, for Spider Score 477, 419, 416, and 401. Then I got mightily confused because if I sorted by “cards left” the score did not move monotonically, but then I figured that’s because the dimaond suit increased our score? Hope so.

    “Strangeness is 0.6131” means 61% of random cases are better than ours

    score 477

    Remaining: A 2 3 4 5 6 7 8 9 T J Q K
    83 left. 6 6 6 8 7 6 8 7 6 5 7 4 7
    Strangeness is 0.6622 (bumpinesss 17)

    score 416

    Remaining: A 2 3 4 5 6 7 8 9 T J Q K
    43 left. 3 4 4 3 4 3 5 2 3 1 4 3 4
    Strangeness is 0.3503 (bumpinesss 17)

    score 419

    Remaining: A 2 3 4 5 6 7 8 9 T J Q K
    27 left. 2 3 4 2 3 2 3 2 1 0 3 0 2
    Strangeness is 0.6131 (bumpinesss 18)

    score 401

    Remaining: A 2 3 4 5 6 7 8 9 T J Q K
    15 left. 2 1 2 1 2 1 1 2 0 0 2 0 1
    Strangeness is 0.4682 (bumpinesss 13)

    Nothing is very far off the expected 0.50 there in any of these. A smal trend towards worse than average luck at first, a small trend towards better than average at the end.

    But, connecting with the GM’s inquiry, I got to thinking about complete suits and what they would surely correlate with. Another way you can achieve order is through in-suit pairs. A complete suit has 12 of them. But long runs in suits that aren’t fully complete also indicate order. Lots of doubles that can be moved as a unit are also good; goodness does not rely only in long runs.

    So, another program! This one is more tedious to use because you have to input suit as well as rank. (In the output, Suit0 is spades, Suit1 is hearts, etc., because the programmer was too lazy to spell them out).

    So, those same 4 points according to this new measure:

    score 477

    C:\Cpp Programs\Hello>spiderinsuit
    Enter ranks of suits in 4 lines, as prompted.
    Spades: 56qa93
    Hearts: qjt
    Diamonds: 6qqa29t
    Clubs: t238k
    Found: A 2 3 4 5 6 7 8 9 T J Q K
    Suit0: 1 0 1 0 1 1 0 0 1 0 0 1 0
    Suit1: 0 0 0 0 0 0 0 0 0 1 1 1 0
    Suit2: 1 1 0 0 0 1 0 0 1 1 0 2 0
    Suit3: 0 1 1 0 0 0 0 1 0 1 0 0 1
    Total cards: 21
    6 ‘rank buddies’
    Our results compared to expected:
    Better 34588 ( 0.3459)
    Same 21489 ( 0.2149)
    Worse 43923 ( 0.4392)

    score 416

    Spades: 856t3a2q6t879
    Hearts: 89t45346a96tjqk
    Diamonds: a28tjqkqk434-t
    Clubs: j52t97a234qj8qk
    Found: A 2 3 4 5 6 7 8 9 T J Q K
    Suit0: 1 1 1 0 1 2 1 2 1 2 0 1 0
    Suit1: 1 0 1 2 1 2 0 1 2 2 1 1 1
    Suit2: 1 1 1 2 1 1 1 2 1 2 1 2 2
    Suit3: 1 2 1 1 1 0 1 1 1 1 2 2 1
    Total cards: 61
    40 ‘rank buddies’
    Our results compared to expected:
    Better 63253 ( 0.6325)
    Same 13085 ( 0.1308)
    Worse 23662 ( 0.2366)

    score 419

    Spades: a-4865-ttqqka
    Hearts: a42-qk69-qk
    Diamonds: a-k5qk9t48
    Clubs: a672tjqa-57k8-q9

    Found: A 2 3 4 5 6 7 8 9 T J Q K
    Suit0: 2 1 1 1 1 2 1 2 1 2 0 2 1
    Suit1: 1 1 1 2 1 2 1 1 2 2 2 2 2
    Suit2: 1 1 1 2 2 1 1 2 2 2 1 2 2
    Suit3: 2 2 1 1 1 1 2 1 2 2 2 2 1
    Total cards: 77
    58 ‘rank buddies’
    Our results compared to expected:
    Better 73589 ( 0.7359)
    Same 12286 ( 0.1229)
    Worse 14125 ( 0.1412)

    Checksum: 17 hidden + 10 (1 deal) = 27. 77+27 = 104.

    score 401

    Spades: ja-t7a8963qt5qk2
    Hearts: 24a3-qk69-q2k
    Diamonds: a-k53qk6479t8
    Clubs: 6792tkajqa-57k8-q4
    Found: A 2 3 4 5 6 7 8 9 T J Q K
    Suit0: 2 2 2 1 2 2 2 2 2 2 1 2 1
    Suit1: 1 2 1 2 1 2 1 1 2 2 2 2 2
    Suit2: 1 1 2 2 2 2 2 2 2 2 1 2 2
    Suit3: 2 2 1 2 1 1 2 1 2 2 2 2 2
    Total cards: 89
    72 ‘rank buddies’
    Our results compared to expected:
    Better 47777 ( 0.4778)
    Same 22093 ( 0.2209)
    Worse 30130 ( 0.3013)

    (15+89 =104)

    Results: The first deal and the last deal reveal average luck. But at points with scores 416 and 419, we have notably better than average luck. Better than 63% of average deals, worse than only 24% in the one case, better than 74% better and worse than 14% on the other. (Statistically significant? Beats me. But the statisticians all say that’s the wrong measure anyway… Confidence intervals anyone? Or something else…)
    76/14

    ——————-
    I am happy to provide .exe files that run on Windows 10 — though your computer will scream warnings at you multiple times, since viruses come in .exe and who heard of sharing programs?

    I am also happy to provide C++ code that compiles with a 1998 Microsoft compiler, using almost exclusively C features.

    ———————–

    *Note by the picayune reader on base post: The Maximum for a full suit is 97, no? 96 is the most you can get WITHOUT getting a full suit?

    **In my first run I had an error in the suit-level analysis in 416, in that I was missing a queen of spades. Without the queen, it was better than 76%, but with the queen it dropped to 63%! Since that didn’t change the number of in-suit pairs, the only effect was the total number of cards, 40 rank buddies in 61 cards as opposed 40 in 60 cards. The more cards you get, the more rank buddies you expect, but that’s extremely sensitive! Or else there’s a bug somewhere.

    Like

  2. READ FIRST. The previous post was supposed to be preceded by this short summary:

    tl;dr. Looking at number of adjacent in-suit pairs (like QK of spades) as a measure, we had notably better than average luck at “score 419” (77 cards visible) but only marginally so at reasonably nearby “score 416” on the one side and none at all at “score 401” on the other. If we look only at ranks and do not account for suits, our luck was average throughout.

    Like

Leave a comment