Dave Martin
# Mathcad Community Challenge January 2024: Factorials and Permutations and Combinations, Oh My!

- 2/21/2024
- Read Time : 4 min.

This month’s challenge was based around shuffling a deck of cards. It’s inspired by this article.

The challenge was to perform the following in PTC Mathcad Prime:

- Calculate the number of ways to shuffle a deck of cards (standard 52 card deck)
- Calculate the number of ways to shuffle a deck of cards if the suit (heart, diamond, spade, club) doesn’t matter
- Calculate the number of ways to shuffle a deck consisting of just the face cards (jacks, queens, and kings). If you could shuffle the deck one time a second, how long would it take to shuffle each possible way? (Express the result in hours, days, or years)
- How long would it take to shuffle the face cards until there’s a 0.5 probability you’ve shuffled the same way twice? If you add the aces, how long would it take for that same 0.5 probability that you’ve shuffled the same way twice?
- Create a Chart Component to depict the number of ways to shuffle a deck from one to 12 cards
- How many cards would be in a deck in which the number of ways to shuffle would be on an order of magnitude with the number of atoms in the Earth? What about the universe? Assume 10 to the 50th power for number of atoms in the Earth and 10 to the 80th for the universe.

Four people accepted the challenge. First though, let’s talk about…

The first challenge is a straight 52 factorial, but I find the big surprise to be how big a number it is—8 times 10 to the 67th power! Jean-Christophe from PTC added an interesting post about how long 52! seconds is, including walking around the Earth one step every billion years, emptying and refilling the Pacific Ocean one drop at a time, and stacking paper from the Earth to the Sun.

When the suit doesn’t matter, the answer drops to about 9 times 10 to the 49th power—a number on the order of the number of atoms in the Earth!

Even 12 factorial (a deck consisting of the face cards) is a big number. Twelve factorial seconds comes out to over 15 years. The number of atoms in the earth is between 41 and 42 factorial, and the number of atoms in the universe is around 59 factorial.

*View the full responses on the PTC Community now*

Frequent contributor **Werner E.** was the first to respond, within hours on New Years Day. The worksheet looks very nice with the gridlines turned off and the frame turned on. The math uses a variety of tools, including but not limited to the Product operator, symbolic evaluation with keywords, programs, and the root function.

However, documentation is one of the key strengths of Mathcad. I always encourage people to create their worksheets so that they can stand on their own. As an instructor and an author, I encourage you to find a tone that seeks to educate and illuminate.

**Fred Kohlhepp** provided an efficient worksheet that solved all the challenges within two pages. As a teaching worksheet, it makes great use of text, text color, and highlighting to draw a reader’s eyes to the important parts.

Fred makes nice use of citing internet references so that people can dig in more. The hyperlink functionality would be great in this situation, to save people from copying and pasting the references in a web browser.

I like the use of XY Plots with Stem Traces and markers on log scales to convey the challenges graphically.

**Alan Stevens** solved the fourth challenge in the same way that I learned how in a room of 23 people, there’s a greater than 0.5 probability that two of them have the same birthday. Since Alan performed the challenge in Mathcad Express, he could not make use of Solve Blocks to find the answer. So he derived an approximate solution involving natural logs and summations. I like the use of the comparison equals sign operator to document the logic.

By the way, it would take over seven hours to shuffle a deck of the face cards until you’ve exceeded a 0.5 probability that you’ve shuffled the same way twice. Add the aces, and that time increases to over 62 days!

Alan also breaks out Stirling’s approximation for large factorials to solve the final challenge. As always, Alan delivers a worksheet that could be used as a teaching tool in a high school or college classroom.

**Germano Freitas** delivered the final entry for the challenge. The numbers we’re dealing with are so large that Germano’s Product function exceeded Mathcad’s limits, so he had to round the solution between five and six million permutations. He also solved the last two challenges manually, which is the first approach that I took.

Although no one used the Chart Component to depict the numbers from one to 12 factorial, I like Germano’s use of a Column Trace in the XY Plot. (Everyone did use a log scale, which helps to show how fast factorials blow up.)

Usually when I think of Mathcad, I leap to engineering calculations. I like this challenge because everyone is familiar with a deck of cards, and it helps to illustrate the power of factorials, permutations, and combinations. If you haven’t tried any part of this challenge yourself, I encourage you to check out the submissions and grab a copy of Mathcad Express to explore other questions about a deck of cards. If Monopoly or Dungeons & Dragons are more your cup of tea, what kind of math problems can you explore?

Get the latest Mathcad Community Challenge, plus other Mathcad tips, tricks, and more!