My kids have recently become really interested in card games. Yesterday I was chatting with my younger son about shuffling and how you might be able to tell if the cards were well-shuffled. He thought that there was no way to tell.

Following that conversation I thought I’d talk to the boys about entropy and card shuffling. The link below popped up basically immediately on a google search, and the first comment basically wrote the project for me . . . .

See the first comment on this Stackexchange post

In the first part of the video below I introduced the problem and had the boys talk about what they thought about shuffling. They had some interesting ideas and noticed that some simple ways of measuring the disorder wouldn’t actually be very good. That discussion showed me that the general idea of entropy was actually accessible to kids.

The tricky thing about the entropy calculation is that it involves the logarithm function, so I used the second half of the video to do a quick and dirty introduction to logs.

Next I showed them how the Shannon Entropy calculation would work for a deck of cards. Here’s the simplified explanation of the procedure (and the comment on the Stackexchange thread linked above has R code that implements this procedure):

(1) Number the cards

(2) After each shuffle – look at the difference in the numbers of adjacent cards. If that difference is negative, add 52 to make it positive.

(3) Count how many of the differences are 1, 2, 3, and so on.

(4) Divide the count in each bucket by 52 to turn the counts into probabilities.

(5) Add up the probability times the log of the probability for each bucket that had a non-zero count.

(6) Take the number in (5) and multiply by -1 -> that’s the Shannon Entropy.

Here’s my explanation of this process as well as the first shuffle:

Next we looked carefully at the first shuffle – the boys thought it was more random that the unshuffled deck, but still had a lot of structure. When we went through the entropy calculation we found the entropy had moved from 0 to about 1.65.

Next we did 4 more shuffles off camera and recorded the results. Then I had my son do 5 successive shuffles (of the already shuffled deck) to produce a deck that had been shuffled 10 times. In this video we calculated the Shannon Entropy of the deck for all of those shuffles and looked at the results.

Finally we went to the comment on the Stackexchange question. Here we looked at the graphs included in that comment and also compared our results to the computer-generated ones. One surprise that our entropy grew very fast compared to the computer shuffling. Both entropy calculations ended up around the same number, though (which was pretty cool!).

This was a really fun project and one that I think many kids would find fascinating. Obviously the including of logs presents a bit of a challenge. Since I wasn’t planning on doing a super deep dive into the entropy calculation, I effectively just skipped over the logarithms. The main idea that I wanted to communicate to the boys was that there actually is a way to measure disorder, and the process isn’t actually that complicated. I really enjoyed this one!