Prelude:

A few words to the reader before they dive in:

I often make independent mathematical explorations for fun, which has prompted me to want to share them in either blog or video form. Writing in English feels easier and more natural to me, so I'll do that. I want to make mathematics accessible and fun to people who don't enjoy (yet) or don't consider themselves "good at math".

Writing for blogs or texts in general has proven to be fun, yet challenging, especially when it comes to explaining mathematics. It is particularly difficult to balance clarity with humor, brevity and lightness. On the one hand, I don't want to write a dry and boring textbook. I want to portray what mathematics is to me: an engaging, fun, exploratory, intuitive, creatively frustrating process. On the other, I don't want my readers to feel lost, confused and dejected. Mathematics can be fun, interesting and challenging, but it can also be intimidating, overwhelming and tedious. But the biggest danger I wish to avoid is making my reader feel stupid for not understanding a bad writer's attempt at explaining mathematics.

So while you're reading, I just want you to know two things:

  1. You are not stupid, I'm just a bad writer. Really. It's not your fault for not understanding, it's MY fault for not being clear enough. If there's anything you didn't understand, please tell me. I'd be more than happy to clarify, and knowing when this happens is valuable feedback for me to improve my writing by calibrating the balance between clarity and brevity. Sometimes I can have my head so far up my own ass, I'll assume things are obvious when they're not. Besides, a misinterpretation can (and often does) spawn new, interesting ideas!
  2. Don't get too caught up in the math. Yes, I'm writing about math, but you can keep reading even if some aspects of the math are not clear. I'll always take care to write out my findings and conclusions, putting everything into context so that even if you missed the math, you can still get the point.

Adventures in Card Shuffling

When I was little, maybe 6-7 years old, I often marveled at the infinity of everything around me. To my parents' exasperation, these epiphanies often struck in the shower- my private sanctuary for deep thought. I watched water droplets slide down the wall, each forming for a brief, unrepeatable moment. Never again would I see that exact arrangement of atoms, those precise paths formed by water on the wall. It was like staring into a kaleidoscope of endless possibilities, beautiful, yes, but also a bit tragic, much like the realization that I would never be able to count up to all the numbers. How was I supposed to shower quickly while grappling with such sublime, terrifying truths about the nature of the universe as an ever-changing series of ephemeral states, of which we get to witness only one of infinitely many possible sequences?

In an attempt to conquer infinity, I decided to first tackle something smaller: a deck of cards. Surely, I thought, here was something finite, something manageable, something I could control. My domain, my kingdom, no matter how small or simple. I spent hours and hours shuffling and re-shuffling that deck in precise, exact, repeatable ways. A behavior which, when witnessed by adults, spawned such curiosity and even ridicule I've yet to comprehend. I might have looked bored (or boring) on the outside, but on the inside, I was playing with the very fabric of order and chaos, completely engrossed in the present. I analyzed how each shuffle bent the sequence of cards. Sometimes, if I repeated a shuffle 2, 4 even 12 times, the deck would return to its original order, as if the universe was cooperating with my need for control. Other times... not so much. Time would run out, and I'd leave the cards in a mess, wondering if I'd ever be able to bring them back to order through the same process of shuffling. Was Baby Dany chasing another impossible dream?

Playing with a deck of cards is a humbling reminder of how small we are, how limited, how infinity lurks around us, hidden in plain sight, just beyond our reach.

No, really.

Even now, at the age of 29, I still feel the itch- the irresistible urge to shuffle a deck systematically, as if, through sheer persistence, I might someday glimpse every possible ordering of those 52 cards.

This is where the allure of mathematics truly shines for me. It starts with a question that intrigues me, pulling me into a world where I'm prompted to discover-or invent- the mathematical tools to answer it. It's my personal call to adventure in the well-known Hero's Journey. I imagine it's what our ancestral mathematical geniuses felt too. Like a painter paints, a dancer dances, a mathematician... maths?

My rabbit hole today is inspired by this question: How many times do you need to repeat a particular shuffle to return a deck to its original order? And, to spice it up, what's the shuffle (or shuffles) that require the most repetitions? The largest shuffle, the shuffliest shuffle, if you will.

Since I'm writing for "normal" people who have not, presumably, spent hours shuffling decks or exploring mathematics for fun like me, I'll need to clarify a few notions first. Fret not, though! You'll find that "advanced" mathematics are not more difficult, rather just more abstract, focusing on concepts and relationships. The best part? It usually requires little to no mental arithmetic. There's a reason professional mathematicians have a reputation for being bad at adding or multiplying mentally!

What is a shuffle?

First, what do I mean by a "shuffle"? Sure, you know how to shuffle a deck of cards in real life, such as the satisfying "riffle shuffle" motion of cutting the deck roughly in half and interleaving them, and yes, that is a valid shuffle. But here, a shuffle needs to be precise and well-defined-no randomness allowed- so it can be repeated exactly the same way over and over again. If you can do that with the riffle shuffle, then hats off to you!

For example:

  • Switching the first two cards of the deck and doing nothing to the rest. When repeating this shuffle twice, the deck returns to its original order.
  • Moving the card on the back of the deck to the front. Repeating this shuffle 52 times (since there are 52 cards in a deck) returns the deck to its original order.

So let's say, for the previous two examples, their "shuffle numbers" are 2 and 52, respectively.

Mathematically speaking, a shuffle defined like this is known as a permutation, something that may ring a bell from high school, tucked away safely somewhere in the part of the brain that stores information it does not care about. Stay with me, though, because we're going places.

A permutation is nothing more than a rearrangement of items. A 52-item collection, such as a deck of cards, has 52! ways to re-order it. The little "!" symbol, mathematically, represents a factorial- that would be \( 52 \times 51 \times 50\times ... \times 3 \times 2 \times 1,\) which is a prohibitively HUGE number. It's around \( 8.065 \times 10^{67} \). To put it into context, the number of atoms in the entire observable universe is estimated around \( 10 ^ {78} - 10 ^ {82} \). If you shuffle a deck of cards randomly, odds are the particular order of cards you just obtained has never been seen in the entire history of humanity. It's THAT big. When compared to how little time we get to spend on Earth as humans, that number is practically equivalent to infinity. Bad news for Baby Dany- it seems like her ambition to achieve all possible card deck orderings is a bit out of reach.

I could make a computer program that simulates each possible shuffle, repeats it until the deck is re-ordered again and records the "shuffle number" of each possible shuffle, assuming all shuffles do eventually return the deck to order. That's easy enough. I can code that in less than 10 minutes, which is good because I would need to start running it NOW so that it might finish running by the time the universe ends...

Computers are a lot faster than humans at computing (so computers compute... do humans... human?), but they're not infinitely fast. Let's say the computer can analyze 10,000 shuffles per second. It would still require \( 2.55 \times 10 ^ {56} \) years to finish analyzing all of them. They're just as hopeless as we are at tackling this problem, so take that, computers!

This is where math comes to the rescue, to extend today's computer's limitations.

I guess we need to get better acquainted with permutations...

To get to know permutations a little better, let's starts small. Instead of tackling 52 cards right away, let's work with 7 items. Why 7? Well, it's a manageable size and it's prime- my math intuition tells me it might be relevant. Maybe not, it's just a wild guess.

We'll represent these items as \( [a, b, c, d, e, f, g] \). Simple enough.

Now suppose I make a shuffle where I swap the first item with the second. To represent this in a quick way, we can express it as \( (1 \rightarrow 2) \). Since nothing happens to the rest of the items, we don't need to bother writing them out in the permutation. So after one shuffle, the order is:

\[ [b,a,c,d,e,f,g] \]

And if we repeat the shuffle, we would switch the first and second items again, obtaining:

\[ [a, b, c, d, e, f, g]\]

So we have a cycle where the permutation "resets" after 2 repetitions. The "shuffle number" here is 2, as mentioned above.

Mathematicians drop the arrow notation in favor of a simple parenthesis, because writing arrows constantly would be cumbersome. We're nothing if not practical. We'll use more compact notation to represent the swap: \( (1, 2) \). It's more elegant, short and sweet. It means "the first item moves to the second place, and the second item moves to the first place". A little 2-item cycle.

What if we made a larger shuffle by cycling three items? Let's say, the first item to the second place, the second item to the third place, and the third to the first. This creates the cycle: \( (1, 2, 3) \)

Note that \( (1, 2, 3) = (2, 3, 1) = (3, 2, 1) \) since a cycle is the same no matter where it starts. The overall switching instructions are equivalent.

Applying that cycle once gives us:

\[ [c, a, b, d, e, f, g] \]

Twice:

\[ [b, c, a, d, e, f, g] \]

And a third time:

\[ [a, b, c, d, e, f, g]\]

So the shuffle number here is 3 because it takes three repetitions to get back to the original arrangement. This is a 3-cycle. Do the positions in the cycle have to be consecutive or in sequential order? No. I could just as easily pick \((1, 5, 7)\) or \( (2, 1, 3) \) as 3-cycles, and they will behave the same way as the \( (1, 2, 3) \) cycle in terms of their repetitions, they're just harder to read and visualize. For our sanity, we'll stick to the easiest, most straightforward cycles. That's what mathematics is all about- cutting away the noise and focusing on what really matters in pursuit of elegant, simple, beautiful conclusions.

Thus far, we've come to understand that the length of the cycle is how many times we'd have to repeat the shuffle to reset the deck. It seems, therefore, that Baby Dany was onto something when she was repeating shuffles over and over again! The largest shuffle number for 52 cards may be big, but it's definitely not infinite.

Does this mean that a 7-length cycle has the maximum shuffle number for 7 items? Plot twist: no.

The plot thickens... (aka mixing cycles)

We don't need to limit ourselves to one cycle per shuffle. We can make two (or more) independent cycles in a single permutation. Check this one out: \( (1, 2, 3)(4, 5)\). This one cycles the first three elements and the following two independently. Here's how it looks when applied over and over again:

\[\begin{matrix}[{\color{blue}c, a, b, } {\color{red}e, d,} f, g] \\ [ {\color{blue}b, c, a,} d, e, f, g] \\ [a, b, c, {\color{red}e, d,} f, g] \\ [{\color{blue}c, a, b,} d, e, f, g] \\ [ {\color{blue}b, a, c,} {\color{red}e, d,} f, g] \\ [a, b, c, d, e, f, g] \end{matrix} \]

If that left you cross-eyed, just remember: the first three elements are cycling independently from the next two. Follow the color code: The blue elements are from the first cycle, the red elements are from the second cycle, and black elements are in their original position. You may notice that in order to get both cycles to "sync up" back to the original order, I had to apply the permutation six times. So how does this "syncing" notion work?

For a cycle of 3 items, applying the permutation 3, 6, 8, 12, 15... times will reset the deck. These are multiples of 3, the cycle length. Similarly, for a cycle of 2 items, applying the permutation 2, 4, 6, 8, 10... times will reset the deck. Again, these are multiples of 2, the cycle length.

The smallest number where these two sequences coincide has to be a multiple of both 2 and 3. That is, by definition, the least common multiple of 2 and 3. Yes, that exercise from elementary school we used to loathe in order to find the least common denominator when adding ~spooky~ fractions? Yep, the very same.

With this in mind, we can analyze a riffle shuffle on 10 elements. You'd cut the deck in half and interleave them, such that you'd get:

\[\begin{matrix}[{\color{blue}a, b, c, d, e,} {\color{red}f, g, h, i, j}] \\ [{\color{blue}a,} \color{red}f, \color{blue}b, \color{red}g, \color{blue}c, \color{red}h, \color{blue}d, \color{red}i, \color{blue}e, \color{red}j] \end{matrix}\]

This permutation, in cycle notation, would be: \( (2, 3, 5, 9, 8, 6)(4, 7) \). (Try to work it out yourself, or take my word for it!) This means you have a 6-length cycle and a 2-length cycle. In this case, you'd have to repeat the riffle shuffle only 6 times to reorder the 10-card deck. Not so impressive, is it?

Let's consider another example for our 7-card deck: \( (1, 2, 3)(4, 5, 6, 7)\). The least common multiple of 3 and 4 is 12. This means we've come up with a permutation with a larger shuffle number than 7. The nature of the problem has changed substantially from how we started: in order to find the shuffliest shuffle for 7 items, we need to figure out all the ways we can split the elements into cycles, and find the one with the largest least common multiple.

How many ways can we create permutation cycles for 7 items? The key idea is that the cycle lengths must add up to 7. The items we don't shuffle can be treated as 1-length cycles, which we've been omitting until now for simplicity. The number 7 can be partitioned into a sum in 15 different ways:

\[ \begin{matrix} 7 \\ 6+1 \\5+2 \\5+1+1\\4+3\\4+2+1\\ 4+1+1+1\\3+2+2\\3+2+1+1\\3+1+1+1+1 \\ 2+2+2+1 \\ 2+2+1+1+1 \\ 2+1+1+1+1+1 \\ 1+1+1+1+1+1+1 \end{matrix}\]

Each number in the sum represents a cycle length, so we need to find the partition with the largest least common multiple of its parts. Through brute force, we can see that the partition \( 4+ 3\) yields the largest least common multiple of 12.

This means that for 7 items, the shuffliest shuffle only requires 12 repetitions to reset the deck. Quite underwhelming, considering there are \( 7! = 5,040\) possible shuffles. Is there only one shuffliest shuffle? No, there are many. The only requirement is that they must consist of a 3 and 4-length cycle each. For example, \((1, 2, 3)(4, 5, 6, 7) \) works just as well as \((3, 5, 4)(1, 7, 2, 6) \). You can take my word for it that there are 420 of these shuffliest shuffles for 7 cards.

Now, for 52 items, the partitions are:

\[\begin{matrix} 52 \\ 51+1 \\ 50 + 2 \\ 50 +1 + 1 \\ 49 + 3 \\ 49 + 2 + 1 \\ ... \end{matrix} \]

I'll stop there because listing all 281,589 possible partitions would be very dull to write and read. This is too much for a simple human to analyze, but for a computer, a cakewalk. Creating a program that generates partitions of 52, calculates the least common multiple of the parts, and finds the maximum of these is not just feasible, it's fast! We've effectively reduced infinity to a manageable problem that's easy to compute (for a computer, at least).

In fact, I already did. It took 4.7 seconds to run, and it wasn't even coded to optimize speed or efficiency. That's the power of computers when coupled with mathematics for ya'. Turns out, the largest shuffle number for a 52 card deck is 180,180, and there are three partitions that achieve this:

\[\begin{matrix}13+11+9+7+5+4+3 \\ 13+11+7+7+5+4+2+1 \\ 13+11+9+7+5+4+1+1+1 \end{matrix} \]

The all add up to 52 and have a least common multiple of 180,180. That's it. Those are the only combinations of numbers that add up to 52 and have the largest possible least common multiple. Try as you might, you won't find a better one. You'll never find a shuffle that requires more than 180,180 repetitions to reset the deck.

So, if a shuffle takes you about a minute to perform, you'll need 3,003 hours to perform enough repetitions to reset the deck, at most. That's just 125.123 days! It's still too much for Baby Dany, but she can make do with the idea that it's at least possible to achieve in a lifetime. She could have kept going and yes, she would have eventually reordered the deck.

For mine (and Icha's) sake, I also ran the code for a 72-card deck (aka, Tarot!). It turns out that the shuffliest shuffle is 6,846,840 shuffles long! And the shuffles need to have cycle lengths of \(19+13+11+9+8+7+5 \). This code, however, took over 5 minutes to run (because there are 5,392, 783 possible partitions of 72 into sums of integers), so finding the shuffliest shuffles for large numbers of items is not feasible with this simple analysis. We'd have to find ways to cut corners even more... I'll leave that for next time. I already have some ideas involving the properties of least common multiples, and I'll see if they work out in general. You may notice that the shuffliest shuffles have a lot of prime number cycle lengths, but not exclusively. This is what I expected to happen intuitively, but I'll delve into that another time. We tamed our initial question and we're left with another call to adventure. Remember, we gotta leave room for a sequel!

Humbled yet? Hopefully, the next time you grab a deck of cards, you'll be aware of the infinite possibilities you're holding in your hands, and how humans, through mathematics, can manage to understand, appreciate, and yes, sometimes tame these infinities.

Dany's Adventures in Card Shuffling