Blogs Mathcad Community Challenges 2024 Collection  

Mathcad Community Challenges 2024 Collection  

January 1, 2025 Mathcad Challenges Index  Mathcad Minute Sign-Up 

Dave Martin is a Creo, Windchill, and PTC Mathcad instructor and consultant. He is the author of the books “Top Down Design in Creo Parametric,” “Design Intent in Creo Parametric,” and “Configuring Creo Parametric,” all available at amazon.com. He can be reached at [email protected].

Dave currently works as the configuration manager for Elroy Air, which develops autonomous aerial vehicles for middle-mile delivery. Previous employers include Blue Origin, Amazon Prime Air, Amazon Lab126, and PTC. He holds a degree in Mechanical Engineering from MIT and is a former armor officer in the United States Army Reserves.

See All From This Author

This article is a collection of the five Mathcad Community Challenges that happened in 2024. Each Mathcad Community Challenge is a usually bimonthly occurrence where I post the challenge at the start of the month, and then Community members work independently or collaborate together to solve the challenge by commenting their PTC Mathcad Prime worksheets. Anyone can join the PTC Community and participate!

Green Klein Bottle 3D plot artwork made in PTC Mathcad Prime 

Mathcad Community Challenges 2023 Collection 

Write-ups and solutions of six Mathcad Community Challenges on diverse topics. 

Read Them Here

2024 had five challenges, because one of the challenges lasted longer than usual:

  1. Playing Card Statistics
  2. Perimeter of an Ellipse
  3. Platonic Solids
  4. Game Gallery
  5. Frustums & Pyramids

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

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 math

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.

The submissions

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.

Mathcad Community Challenge January 2024 submissions collage permutations combinations shuffle playing card deck

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 (Mathcad’s unlicensed version with stripped features), 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.)

Where can you go from here?

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 the 30-day Mathcad free trial 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? (See the May 2024 challenge below.)

Mathcad Community Challenge March 2024: Perimeter of an Ellipse

The Mathcad Community Challenge for March 2024 was based on the geometrical problem below:

I am shocked that I have walked the surface of this planet for over five decades without realizing that there is no exact closed-form solution for the perimeter of an ellipse. In school, we learn the perimeter of shapes like triangles, squares, rectangles, circles, parallelograms, and so on, but I feel like schools and teachers conveniently skipped over ellipses. (An ellipse, in case it’s been a while, is the set of points where the sum of the distances from two points—the foci—is a constant.)

Mathcad Community Challenge March 2024 Properties of an Ellipse

The challenge is to correct that oversight. Create a Mathcad Prime worksheet that:

  • Derives, depicts, or shows one (or more) of the various approximation formulas/methods for the perimeter of an ellipse
  • Create a calculator whereby someone can change the values of the semi-major and semi-minor axis lengths in order to find the perimeter.
  • Create a 3D plot of the perimeter as a function of the ellipse semi-major and semi-minor axis lengths.

Although there is no exact solution for the perimeter of an ellipse, this is a fairly well-documented problem. Therefore, documentation in the worksheet is key. This worksheet should be able to stand on its own and be understood by someone with a basic knowledge of calculus (since integrals and infinite series are involved).

Background to the perimeter of an ellipse

If you are interested in learning more about calculating the perimeter of an ellipse, there are websites like Math is Fun, Cue Math, and Numericana. Broadly speaking, the solutions fall into the following categories:

  • Approximation formulas
  • Formulas involving infinite series
  • Formulas that use integration

Let’s dive into the worksheets provided by our intrepid math explorers.

The solutions

This month’s challenge generated quite a healthy discussion, with over 30 forum replies. In accordance with the rules and guidelines, only Mathcad Prime and Mathcad Express Prime submissions will be discussed here. There are ten worksheets we will discuss.

Frequent contributor Terry Hendicott was the first to respond. He provided a concise, elegant-looking, single-page worksheet that is easy to understand. After setting up variables and function definitions, he used a range variable to display the ellipse on an XY plot. He used a definite integral formula that calculated the perimeter accurate to ten significant digits.

Not satisfied with that, Terry contributed feedback on the work of others and submitted a worksheet with a second approach. There’s quite a bit of matrix work involving trigonometry functions, but he managed to plot perimeter as a function of the two semi-axis values on an XY plot. In other words, he managed a 3D plot on a 2D plot. Ingenious.

Valery Ochkov provided a couple worksheets that I would normally fault for lack of documentation, but I assume English isn’t his first language since he resides in Russia. He used symbolic evaluation to solve the equation for an ellipse in terms of y, and then used symbolic evaluation to find the derivative of that solution. He then used a function that incorporated that solution in a definite integral. He graphed that function on a 3D plot, making use of the Try/On Error programming construct.

 

I can always rely on Alan Stevens to submit a well-documented worksheet that could appear as a chapter in a math textbook or a teaching aid in a college class. Rather than use one of the existing publicly available formulas, Alan derived his own. His method involved expansion and integrals based on the derivative of the ellipse function, and the logic is well explained. Alan even wrote and plotted a formula to calculate the error in the perimeter based on the ratio of the semi-major to semi-minor axes.

Mathcad Community Challenge March 2024 Ellipse Perimeter Collage

User DJF formulated an approach based on the method Archimedes used to calculate the circumference of a circle and the circle constant pi. Another original approach. He wrote a program for the vector of x-coordinates of the ellipse subdivided into a thousand segments, vectorized the value of the y-coordinates, and calculated the length. He increased the number of subdivided segments progressively up to nine million to show how the solution converged on a result.

Bert Beirinckx did two special things in his worksheet. He was the first to solve for the perimeter using polar coordinates instead of more traditional Cartesian coordinates. (The ellipse is also graphed on a Polar plot.) Second, Bert plotted the perimeter as a function of the semi-major and semi-minor axes on a Contour plot. This might be the first time I’ve seen a Contour plot in a Mathcad challenge.

Frequent contributor ppal calculated the perimeter in a brief worksheet using Ramanujan approximations. However, as ppal notes in a quote in a text box, Ramanujan never explained how he came to this approximation. Fascinating, given how often his name comes up in discussions about ellipses.

The final Mathcad Prime submission was from Fred Kohlhepp, another frequent contributor. Like Bert, Fred solved using polar coordinates. Knowing the distance of any point from the center in terms of the angular coordinate, he integrated over the extent of the polar coordinate. However, Fred got an incorrect result. This is where community comes in. Fred posted about the error, and Alan Stevens provided insight into the correct solution.

The takeaways

This month’s challenge once again exemplifies a common theme we’ve seen from previous months. Mathcad users have a variety of techniques and tools to solve the same problem. For calculating the perimeter of the ellipse, we had approximation formulas, Ramanujan approximations, infinite series, and integrals. People used variables, functions, derivatives, matrices, symbolic evaluation, programs, and polar coordinates. Solutions were graphed with XY plots, Polar plots, Contour plots, and 3D plots. The math was supplemented with documentation including text, images, headers, footers, and hyperlinks.

To spark your creativity and approach your next problem with a fresh outlook, browse through this month’s submissions!

Mathcad Community Challenge May 2024: Platonic Solids

The May 2024 Mathcad Community Challenge was inspired by Dungeons & Dragons and the Netflix show Stranger Things:

D&D involves spinning dice, which are regular convex polyhedrons. Common dice include the d4 (tetrahedron), d6 (cube), d8 (octahedron), d12 (dodecahedron), and d20 (icosahedron), where ‘d’ is for die and the number indicates the number of sides. Platonic solids are regular polyhedrons made up of regular polygons (the lengths of each side and interior angles are equal).

Your challenge is as follows:

  • Derive the surface area of the regular polyhedrons as a function of the radius of a circle that circumscribes a polygonal face.
  • Create a calculator where the user can select a regular polyhedron by its name or number of sides, and for a given radius of the circumscribed circle of the polygonal face, the surface area and volume will be calculated.
  • After the user selects a polyhedron, the number of vertices, number of edges, and Euler characteristic for the polyhedron should be displayed on the worksheet.
  • Using the Chart Component, graph the surface area and volume as a function of the number of faces.

The submissions

For this challenge, four people submitted five worksheets. Let’s take a look at their responses.

Frequent contributor Tokoro was the first to submit a worksheet. He submitted a second one later in the month. Right off the bat, his worksheet takes advantage of the new advanced input controls in Mathcad Prime 10, including the slider (to change the radius of the circumscribed circle), a check box to fill the surfaces, and a list box to select one of the various polyhedrons. The second submission included more check boxes to plot the circle and the radius.

Tokoro's polyhedrons worksheet with Mathcad Prime 10 Advanced Control checkboxes turned off and on

If you view Tokoro’s worksheets, be sure to look at what he has in the Draft view. He uses a Table for all the polyhedron properties, including functions for the edge length, surface area, and volume. (I didn’t know you could include functions as table entries. Neat.) There’s symbolic evaluation including substituting the circumscribed circle radius for the edge length. The main part of the worksheet plots each of the polyhedrons in their own 3D Plot and uses an XY Plot for surface area and volume as a function of the number of faces.

Alan Stevens starts with the formula for the area of a polyhedron as a function of the number of faces, number of edges per face, and radius of the circumscribed circle. He cleverly wrote a function that returns the parameters of a polyhedron based on its first letter and a Boolean comparison. A second function returns the polyhedron properties based on the first letter and radius. He then created an XY Plot that shows a column trace of the area as a function of the number of faces.

A collage of Alan Stevens', ppal's, and Patrick H's platonic solids Mathcad Prime 10 worksheets

ppal’s worksheet starts off with documentation and images; that’s always nice. You can select the shape from the new List Box input control. Then a program calculates the polyhedron properties based on the selection. Those properties are reported in a matrix. ppal uses the currency symbol as a placeholder for the length dimension. Interesting; I had never seen that used before.

Patrick H defined a series of programs like a set of subroutines. The last program in that series calls the subroutines to calculate the characteristics of a polyhedron. He also used the new List Box input for selecting the polyhedron. The surface area and volume as a function of the number of faces were graphed using the Chart Component with a second Y-axis.

Then for bonus points, he wrote programs to make 3D plots of each of the Platonic solids. I recommend downloading this worksheet so you can click on each of the 3D plots and spin the polyhedrons around.

Next steps

I did not expect to see use of the advanced controls so early after Mathcad Prime 10 released. I am personally very excited about this Mathcad Prime 10 functionality. It expands the ability of users to create worksheets that serve as reusable tools for engineering design work and help educators make worksheets to serve as teaching tools.

Data image

Advanced Controls Master Class

Download common scripting examples and learn from the pros about advanced controls.

Get Free Resources

As always, if you want to expand your skills with Mathcad, download the worksheets from this month and previous months. I guarantee you will learn a lot!

Game Reviews for the Mathcad Community Challenge Summer 2024: Game Gallery

Editor’s Note: This section of the Mathcad Community Challenge 2024 collection is written by PTC’s David Newman.

Videogames? In PTC Mathcad Prime? It’s more likely than you think.

The Mathcad Community Challenge Summer 2024 lasted three months, which is three times longer than they usually last. Why the lengthy time period? Because the ask was for Mathcad users to become game creators using PTC Mathcad Prime as the main game design tool, and game design is a lengthy process. Mathcad isn’t meant to be used for games, but that’s why it’s a challenge.

This challenge is made possible thanks to PTC Mathcad Prime 10 bringing Advanced Controls into the product. Advanced Controls bring previously impossible levels of automation and user interactivity to Mathcad worksheets, which are some of the ingredients required to develop a game. The other ingredients are the designer’s creativity, both for the game’s vision and to create workarounds when you encounter limitations on implementing your original plan.

I’ll be reviewing the three games submitted for the challenge for this article, and you can download and play all them if you have Mathcad Prime 10 (or later).

All three of these games are of different genres and have very different gameplay loops and implementation styles, so you’ll be able to experience a broad range of design techniques. Besides having fun, you’ll also be able to be inspired by some of those techniques and be able to apply similar principles to your day-to-day engineering work. That’s one of the beauties of game development: it pushes you to think of problems and their solutions you wouldn’t have before, and then you can see things in a new light with insights that you can use in other contexts. This is a lengthy article, so you can scroll through it in this order, or click directly to jump down to their section: MOO, Noughts & Crosses, and then Escape the Gem Tunnels.

MOO, aka Bull & Cows

Download MOO from this attachment on PTC Community.

What is MOO and how do you play it?

MOO has been around for over five decades on significantly more primitive computers than what we have today. It’s a form of code-breaking game. The program generates a four-digit number, but it’s hidden from the player’s view. You must submit your own four-digit numbers to try to guess the hidden number, and the program provides you feedback based how close you were. If you got the correct digit in the correct place, you’ll get a Bull. If you get the correct digit in the incorrect place, you’ll get a Cow. Otherwise, you’ll get a nil. For example, if you guess 1234 and the code is actually 2354, you’ll be told “BCCn”. You aren’t told which digit corresponds to which piece of feedback; you’ll have to deductively reason that on your subsequent guesses.

How is MOO implemented in Mathcad Prime?

This Mathcad implementation of MOO follows how it was implemented decades ago (with a handy hyperlinked citation at the end). The first page has very useful instructions of how to play, while all of the gameplay is on page two.

The first thing you’ll do is check which mode you want with an Advanced Control Checkbox: whether the randomly generated number will not have duplicates or if it could have duplicates. This changes how you approach the game and with-duplicates is a bit more difficult. The checkbox is handily labelled. Then there is a collapsed area with the native Mathcad program that actually generates the number, using the value of the Duplicates checkbox to determine which number-generation sequence to run. This is collapsed because this program also reveals what the actual answer is. Note that the original MOO did not have duplicates available, so that is a feature implemented for this rendition.

What follows is the iterative gameplay loop: Type your answer into the writable Text Box Advanced Control (this has several checks on what you type in to make sure it is a four-digit number) and then click the Button Advanced Control to “Click to Check Your Answer!” This will update the read-only Text Box located below where you submit your guess, and also make your write-in Text Box read-only. That Text Box compares the hidden number with your number digit-by-digit and then provides your Bull, Cow, and nil count. The box also changes colour based on how close you are (pure red = bad, pure green = win, and then the several gradients in-between those).

You then click the Check Your Answer button again (it is now converted to “Click to Guess Again!”), which clears the results Text Box and allows you to write into the guess Text Box again. You keep guessing (and Mathcad will keep track of how many guesses you have, as in, the number of times you click “Click to Check Your Answer”; when the Button is in the “Click to Guess Again!” state, clicking it will not add to your guess count) until you get four Bulls, and then a message pop-up box will appear congratulating you.

You may be wondering why the Button Advanced Control switches between Click to Check Your Answer and Click to Guess Again. That is because Mathcad Prime works from top-down and left-to-right, and this applies to Advanced Controls as well. There is no way for the contents of the top of the worksheet to know what happens at the bottom of the worksheet because the bottom is calculated after the top is. That’s also why the results Text Box can’t be above the user input Text Box. Mathcad’s linear format suggests that an iterative loop is impossible unless you have this workaround like MOO did where you press the button to “release” the results, and this button works based off of human input as opposed to being automated. The game design benefit of this approach is that it allows the player to think about their guesses and the feedback before doing another guess, encouraging more deliberate gameplay. It also gives the player an opportunity to use Mathcad’s text boxes to record their guesses, feedback, and logical deductions from there.

Winning MOO in PTC Mathcad Prime
I know that there couldn’t be a 2 or else the second guess couldn’t have a nil in it. That also means there had to be a 1. Similarly, if there is a 1, the third guess of 1334 having Cnnn means 3 and 4 aren’t possible either, and 1 had to be in slots two or three. (It couldn’t be 4 because the second guess had a Bull.) The fourth guess, 5166, means there couldn’t be a 5 or else there wouldn’t be a nil, and it also excluded slot two from being valid for the 1 digit because there was no Bull, leaving only slot three for 1. It also ensured there was a 6 digit, but not in slots three or four or else they’d have a Bull. 6718 being the correct answer on the next guess was a matter of educated luck; it could’ve easily been something like 9617.

What could’ve been done differently with MOO?

There is a copy-pastable example in Mathcad Prime’s Help Center about making a “Recalculate” Button control, which in this context, would function as a “New Game” button. (You need to recalculate the worksheet to generate a new random number.) Currently, the in-game instructions says to press Ctrl+F5 or use the Calculate button in Mathcad’s ribbon to start a new game. This is quite easy to do, but since everything else in the game can be accessed by clicking on buttons in the main area, or by typing in the box, it’s more consistent design-wise to have a button for a new game.

The bigger thing that I tried to do with MOO, but I couldn’t make happen, was have Mathcad Prime automatically record your guesses and feedback during a game, as opposed to the suggested way of the player manually typing it into a text region. Essentially, my problem was: can Mathcad store a list and keep adding new entries to the list without overwriting the existing entries, and do this action an arbitrary amount of times (where each entry has the same variable name because you don’t know ahead of time how many times it’ll be iterated) as opposed to a single-use program? I don’t think Mathcad can, at least not by itself, and I’m unwilling to try to learn the Mathcad API for this purpose. And it would be a strange user experience to call another program just for this.

Still, there is something to be said about the immersion benefits of having the player focus on recording their own answers. (Or memorise them if you think you can do that.)

Noughts & Crosses

Download Noughts & Crosses from this PTC Community post’s attachment.

What is Noughts & Crosses and how do you play it?

Some people in the world know this as Tic-tac-toe. This is a very famous and easy-to-play two-player game where you have to get three of your symbols in a row, column, or diagonal on a 3x3 board (this leaves eight possible win states; three columns, three rows, and two diagonals). That means the first player (X) not only gets first-turn advantage, but also gets to place 5 symbols while the second player (O) only gets to place 4. As a result, O can’t win in a normal situation, and at best, can tie with X. Game ties are the most common outcome against an opponent who is awake.

How is Noughts & Crosses implemented in Mathcad Prime?

Given what we just discussed about the particular challenges of an iterative game loop like in MOO, I was challenged by Werner on PTC Community to come up with a way to implement a game as simple as Tic-tac-toe in Mathcad Prime. He didn’t think it could be done in a satisfying way, and concluded that Mathcad Prime isn’t at the level that could “create reasonably good and user-friendly games.” Obviously, I disagree with this conclusion, or else I wouldn’t have made a game-themed Mathcad Community Challenge to begin with.

I made Noughts & Crosses in about a week’s time, implemented entirely with Advanced Controls. Tic-tac-toe in particular is actually quite possible to implement because there is a set number of turns (nine), as opposed to other games where the number of iterations is unknown. Because of that, I came up with a workaround to bypass Mathcad’s linear processing structure: prebuild the nine turns into the worksheet, and show the game board nine times. This wouldn’t be possible if we didn’t know how many turns the game would be before the game started, like Three Men’s Morris or Checkers.

Each turn begins with a Radio Button group. The first one, X1 (X player’s first move), has ten selections: N/A (by default) and then nine positions for the nine places on the game board. Below that are nine read-only Text Box controls, and each of these takes the X1 Radio Button selection as an input. If player X selects a given button, such as “TopRight”, the top right Text Box will highlight yellow and an X will appear. The colour highlight is important to emphasise the impact of the player’s move; basic game design principles say the player should always get feedback on their actions, and since Mathcad Prime doesn’t support aural feedback, then we must rely on visual feedback like eye-catching colour changes.

The next turn, O1 (for the O player’s first move), has a similar Radio Button group, but it also takes X1 as an input. There are also nine Text Box controls beneath O1. O1 will have nine selections: N/A and eight positions; the position marked in X1 will not appear as an option for player O. O picks their position and the appropriate Text Box below it will highlight in yellow with O. The selection that X picked a turn earlier will also be already filled in (but with a white background) with the X, because each game board Text Box will continue to take each Radio Button group up to that point as an input.

This cycle repeats until X3, the game’s fifth turn, because that is the first turn where it’s possible for the game to end. At this point, there is a read-only WinCheck Text Box control below the nine Text Box control game board. This Text Box takes the nine Text Box controls immediately above it as inputs and will go through the eight possible win conditions (three rows, three columns, two diagonals). If those eight conditions have Text Boxes that all have Xs or all have Os, then WinCheck declares a winner. Otherwise, it will say there is not a winner yet. Each of these three states (X wins, O wins, no winner yet) has its own unique text message and background colour.

Starting with O3, the Radio Button group will also take WinCheck as an input. If the game is already over because one of the players have won, the Radio Button group selections will only be “N/A” by default and a second message, “The game is over.” Selecting this impacts nothing, but it does serve as player feedback that subsequent actions won’t change the outcome of the game because it’s been decided. In a world where Mathcad Prime can handle an arbitrary number of turns and automatically generate new control definitions if the game isn’t over yet, this wouldn’t be necessary, but in our world where I’ve predefined all nine turns in the worksheet, it’s important for the integrity of the game to have this check.

Nothing else is different in the worksheet flow until the last turn, X5, where WinCheck’s region is bigger and will declare “The game ends in a draw.” if there is no winner after X5 has made their move. There is also a special message if O somehow won as a fun little developer’s bonus (or “easter egg”). We made a point to show that off in the above embedded video.

By the time the game is over, the twin design decisions of displaying the state of the game board after every turn, along with the colour highlight of how the game board changed on that specific turn, allows the game players to scroll through the worksheet and absorb a sense of satisfaction of their game’s unique evolutionary history. This is made possible by Mathcad Prime’s documentation-oriented approach. This closure (and opportunities for learning and reviewing your strategy by effectively dissecting a ”replay” of your match) wouldn’t be possible if I implemented the game in an alternate universe where Mathcad could, for example, implement Noughts & Crosses like you would with pen and paper, all on one game board and not have a separate (but connected) board for each turn.

What could’ve been done differently with Noughts & Crosses?

There are a lot of things that could’ve been added to my implementation of the game, but more fundamentally, it didn’t have to have 95 Advanced Controls in one worksheet. Depending on your computer’s processing prowess and how many other programs you have open (for example, the game runs a lot faster when I don’t have screen-recording software running on the computer!), the game can have unsatisfactory loading times, since any selection made with a Radio Button group is used as an input for every subsequent Text Box and Radio Button after, so your first turn might have Mathcad loading for a while as it updates nine different game boards (made of nine Text Boxes each) and the eight different Radio Button groups after the first one to exclude the selection you just made as an option. There are other ways of implementing this so not every spot on the game board is its own control. I chose to do it that way because it’s the simplest to implement (and as a bonus, the highlighting on a specific square for a specific selection is only possible in my method); adding extra turns to the game board was a matter of copy-pasting the previous turn, changing the variable definitions, changing and adding the input variables to the correct turn, and changing the code to take into account the extra input conditions. A lot of those changes were very rote and easy. But, again, it does mean the game has relatively lengthy loading times.

Editor’s Note from later 2025: It might still not be a good way to program a game with so many advanced controls, but the game seems to run much faster with PTC Mathcad Prime 11.

 

As for additional features, sometimes people are really attached to the identity of being an “X” or an “O”, and have asked for an option where O goes first. So rather than X1 and O1, we might represent player turns as P1.1 and P2.1 (Player 1 turn 1, Player 2 turn 1) and you could let Player 1 be “O” with a mere Checkbox control to toggle that setting.

A much more complicated feature would be to give players the option to have a computer-player opponent rather than another person or with yourself. Conceptually, this probably isn’t hard; for the computer-designed turns (and I’d probably have to have another option to set if the CPU is X or O, so maybe this would be another Radio Button group of CPU X, CPU O, or No CPU), have an algorithm that, based on the previous turns, picks a selection for which game board square to take that turn. The problem is that I don’t know what kind of Tic-tac-toe algorithms exist (people who do know use the minimax algorithm) or what algorithms I would want to put in, since maybe it’s less fun for the player to fight a perfect robot (or if I should just have the computer pick a square at random!), and I wasn’t interested in taking the time to research that for the purpose of the Mathcad Community Challenge. (Would I want my Radio Button group toggling the CPU’s existence to include difficulty modes?) This was more of a proof-of-concept that Mathcad could handle this type of game. Maybe I could iterate on it if there is ever another Game Gallery challenge… Or perhaps a Community member could take on that task!

Escape the Gem Tunnels

Download the Escape the Gem Tunnels .zip file from this PTC Community post’s attachment, and then unzip the contents to your computer into the same directory. The only files you should then open from your file system are 0-read-me-first-ptc-escape-room.txt and 1-PTC-Escape-Room-main-corridor.mcdx.

What is Escape the Gem Tunnels and how do you play it?

Escape the Gem Tunnels is an escape room-style single-player game. Unlike the previous two games described in this blog, Escape the Gem Tunnels’s game design is original and is not trying to be a recreation of an existing game. It is trying to be an entry into the already-existing escape room game genre, although as far as I know, it’s the first escape room ever made for PTC Mathcad Prime.

Escape room games are based around being put in a room, and through a sequence of solving puzzles (which are often scattered around the room to be solved in an ambiguous sequence, and it’s sometimes not immediately obvious what objects in the room are even meant to be puzzles), be able to get the key(s) to leave the room. Escape rooms tend to be obsessed over having many locks and keys, which can come in many different forms. Solving a puzzle gives you a key to use in a lock, which will open a box (might not literally be a box) to reveal a necessary part to solving another puzzle. You might get keys or passwords without having locks to put them in. Or maybe you’ll have the locks first but need to get the keys. Real-life escape rooms run by businesses tend to have time limits in order to increase the tension, add a story element, and also get the customers (these are often team efforts) out of there if they’re taking too long so they can start the next session with the next group. Puzzles test the participants’ mental abilities, like being able to think logically or out of the box, as opposed to things like physical prowess or outside domain knowledge.

How is Escape the Gem Tunnels implemented in Mathcad Prime?

There is more than one room in Escape the Gem Tunnels, as the pluralised name implies: there are three rooms, or themed tunnels, connected by the “main corridor”. Once again, Advanced Controls play an important role in making this game genre possible, but they’re actually not the most important feature, unlike the previous two games that make exclusive use of them. The real most important feature are Mathcad Prime’s areas, which may be expanded or collapsed, and may be password protected or not have protection. Passwords are, for the most part, the “keys” while the password-protected areas are the “locks”, and the contents inside you get to interact with are the “boxes”. That said, how those passwords are provided varies; a lot of times they are provided by an Advanced Control, like a Text Box, in an expanded-but-password-protected area that takes certain things as inputs. Once you solve a puzzle by manipulating those inputs (but you might not necessarily know what those inputs are), the Control recognises that and the Text Box will change its displayed to the password value needed to unlock its area or another area.

As I’ve discussed previously, Mathcad Prime worksheets have to be linear because of how the program processes information (top to bottom, left to right). This makes Escape the Gem Tunnels far easier than a physical escape room or even other digital escape room videogames, where you have a 3D space or a 2D space where information is presented all on the same “level”, as opposed to information at the top having to be resolved before the information below it. Other escape rooms tend to be linear in terms of the solution flowchart, but the information is presented with many possibilities, clues, and leads simultaneously, so it’s more difficult.

Escape the Gem Tunnels, in keeping with how other escape rooms set up puzzles, never requires you to be an expert in a certain math or engineering knowledge domain. The game’s creator (me) isn’t an expert in those things, either. Much like you will find some objects to be suspicious or out-of-place in a physical escape room, you might find the Mathcad-equivalent of that represented in the Mathcad worksheets. Some things you’ll figure out a lot faster if you’re already familiar with the Mathcad Prime user interface and peculiarities. If you lack that kind of knowledge and still want to play, there is an in-game “Hints?” Checkbox (unchecked by default) in each of the tunnels, that once turned on, will activate hint text in Advanced Controls Text Boxes that will provide information making up for that lack of knowledge if the player isn’t as familiar or otherwise gets stuck somewhere.

Implementation notes: Main Corridor

There are a few interesting tricks on the Main Corridor worksheet. From a Mathcad point of view, the time() function will return the current system time with any expression, such as a number (like time(1), or even time(NaN) would work) or a string (such as time(“…”)), and the expression used is arbitrary. The time updates upon recalculating the worksheet. I didn’t want to have the time begin until the player pressed the Button control at the top (defined as StartButton; the worksheet is set to use “time(StartButton)” minus “time(EndButton)”, which is defined similarly), so I set the default value before the button is clicked to “false”. JScript has a Boolean data type, but Mathcad Prime doesn’t represent “false” as an expression because Mathcad lacks a Boolean data type. This means that the Button can just be an error message by default, meaning there is no value of time(StartButton) or time(EndButton) until the user presses on the button. These time() calculations happen in Draft view.

The idea of having the three tunnels hidden behind a very easy password-protected area in the Main Corridor was to introduce a tutorial to the game. Being able to recognise and open password-protected Areas is the core activity of the game, and if you don’t know how to do that, you won’t be able to ever progress. This would also be the only time I could put a tutorial in the game, since the ensuing three tunnels can be done in any order. And the reason there is a lot of upfront text is to benefit people who are lesser experienced with Mathcad.

Implementation notes: Sapphire Tunnel

 

 

There are some fun puzzles here implemented in unconventional ways. You get to interact with an OLE Microsoft Word file with a hint contained within. There is a Slider puzzle that controls a minute hand and an hour hand of an XY Plot clock below. (Not a realistic depiction of a clock in terms of the length of the hands not being a consistent length as it moves, but that’s too much effort to implement.) It’s supposed to correspond to the timestamp on the protected area beneath it, which is a cool application of timestamps.

My favourite puzzle is one that people might not even notice. The prize inside the first password-protected area (and being able to get into that is a puzzle itself) is a Check Box which turns a later Text Box from read-only to writable, which I think is really cool. It also is an admittedly rare example of a not-completely-linear puzzle flow, since that Text Box isn’t immediately after that Check Box. If you do everything in order, you might even notice that the Text Box was read-only, but it makes a lot of sense in-universe and parallels an escape room trope involving physically carrying some kind of equipment from one part of the room to the other. It helps with the gameplay-story immersion.

Implementation notes: Ruby Tunnel

 

 

The defining puzzle here is the eight-question “Quiz Time!” But there are other notable things here. The very first puzzle, without spoiling the solution, may or may not have the player enter Draft View unintentionally. Through player testing, I put in a help text message in Draft View near the first puzzle instructing players on how to get out of it.

Outside of that, pretty much everything is hidden in collapsed areas, besides an enticing Button that says pressing it won’t do anything if you don’t unlock the password protected area above it. That’s where the quiz is, which is a series of eight List Boxes of multiple-choice questions. If all eight List Boxes have the correct selection, the Text Box placed in the expanded-but-password-protected area will reveal the password to the final area of the worksheet. The questions all involve interacting with the OLE PDF file of four oil paintings, such as counting the number of objects or performing an easy arithmetic operation with the object counts. It’s the one time in this game where math is involved, but the level of math isn’t anything more than the occasional simple math problem you might find in another escape room.

Implementation notes: Emerald Tunnel

 

 

The Emerald Tunnel revolves around data (and figuring out what data is relevant and what data is junk), so it shows off Mathcad’s integration with Excel by using the READEXCEL() function (the .zip contains an Excel sheet that the player is never meant to open from the file directory and only meant to look at from READEXCEL(); but trying to cheat by opening the file from the directory still won’t give them any hints) and the Excel Component, as well as tables and matrices. You will never have to write out the READEXCEL() function by scratch, but you will have to fill in one of the arguments as a clue asks. This turns the form of a Mathcad function’s syntax itself into a puzzle, which is of varying level of difficulty depending on the player’s existing Mathcad familiarity.

The Emerald Tunnel also is the only one with an additional external worksheet linking off of it, being the “sidepaths”. The gimmick of the sidepaths revolves around Mathcad Prime’s region tagging and internal hyperlinks, as well as code/decoder tables that is a classic escape room puzzle. There are fifteen tables in the sidepaths, and main goal of the Emerald Tunnel is to find out which sidepath is the correct one, which also will determine which word is the correct code to decode.

The Emerald Sidepaths have two quirks to it that are spelled out with the only Hint in the worksheet, but if it was displayed as help text and not an optional hint, it would spoil the puzzle. Sometimes there was a bug where hovering your mouse cursor over the hyperlink would not display the region tag name that clicking the link would lead you to. I don’t know why this bug occurred, how to replicate it, or if it still exists in Mathcad Prime 10.0.1.0 or onward. The second quirk is that internal hyperlinks in Mathcad Prime brings you to the part of the document where the tagged region is at the bottom of the screen, as opposed to the top of the screen that most other applications will show. There isn’t a way to get around this issue. People who use Mathcad Prime somewhat extensively are aware of this; others who aren’t used to this quirk may be confused and may scroll up instead of scrolling down, ending up on the wrong sidepath and therefore the wrong decoder table. You can confirm what sidepath you’re on by clicking on the region heading and clicking on the Tag button (Text Formatting > Links > Tag in the ribbon interface).

What could’ve been done differently with Escape the Gem Tunnels?

Escape rooms aren’t supposed to have replay value; that is, you’re not supposed to be able to play them again and get a meaningfully different experience. If you go to your local physical escape room and play it, and then go back there a month later and try the same room, nothing about the room will change. Your knowledge of how to get through it will change since you can just repeat the successful steps you already took last time. That’s why all of the Escape the Gem Tunnels YouTube videos have spoiler warnings at the beginning. That said, there were possibilities for the digital game to have semi-randomised experiences. For example, the multiple choice quiz answers in the Ruby Tunnel could have been presented in a randomly sorted order. Also in the Ruby Tunnel, a random number could have been generated behind the scenes to present different graphic puzzles in the XY Plot / slider section. The Emerald Tunnel could have randomly picked what the correct codeword to break was, although that might require some complicated choreography of the READEXCEL() sheet by using WRITEEXCEL() to change what the correct sidepath would be. By contrast, I don’t think anything in the Sapphire Tunnel could have been randomised. Everything there is hard-coded because it’s all based on words or text. The clock puzzle can’t be randomised because I can only set a single area protection timestamp. I could have made it so there would be multiple to choose from and it would be a different puzzle to figure out which is the correct timestamp (and it would be different each time), but that might be too complicated for the sake of adding replay value.

More puzzle varieties could have been employed, of course. One that I had to not implement was anything related to 3D Plots. I imagine there are several interesting puzzles you could do with exploring a 3D Plot space, similar in nature to our Easter Egg worksheet where there is a hidden message if you peel back certain layers. The problem with implementing that is that it requires some… very advanced knowledge on the math of actually making those, and I don’t have that knowledge, nor did I want to be a burden on people who do have that knowledge.

I could have added down arrow imagery in the Emerald sidepaths to make it more obvious that people needed to scroll down upon clicking, since they are brought to the top of the page since the sidepaths start at the middle of each page.

The last thing that could’ve been done differently, and this one is a slight regret, is that I only made two endings for the game. One ending is the normal one for completing it; the other ending you get is for cheating by only pressing the Escape button and never pressing the begin Button in the Main Corridor, so the time taken to complete the game is negative. I could have made different endings for completing the game in under an hour versus over an hour, as a homage to how physical escape rooms tend to have a one-hour time limit, and also to a homage to how some popular videogames give better endings for finishing them faster. (Of course, those games are meant to be replayed over and over, while an escape room is not.)

Concluding thoughts about the Game Gallery

Now you know that it’s possible to make three very different games in PTC Mathcad Prime. There are far more experiences that you could make than just these. I already have ideas for other games if we ever do a Game Gallery challenge again, and I hope you play the games available now!

But even if you’re not a gamer or don’t feel like a designer, there are still some important lessons on how you can make your PTC Mathcad Prime worksheets more user-friendly and more interactive for your end-user, whether that is a client, others tasked with reviewing your work, or yourself in the future when you must revisit an old project. There are several commonalities between a good game’s user experience and the engineering documentation capabilities that Mathcad has always been an industry leader at providing. Even if you are just putting together a run-of-the-mill report with calculations, you're still designing an experience for someone whether you know it or not.

Check out the archive of all of the previous challenges we’ve had; you will learn a lot about Mathcad Prime techniques and different engineering domains by reading through these.

Mathcad Community Challenge November 2024: Frustums & Pyramids

The Mathcad Community Challenge for November 2024 was based around pyramids and frustums (a pyramid that’s had its top removed by a plane parallel to the base). Click to the challenge thread on PTC Community to download all of the Mathcad Prime worksheet submissions.

The challenges

Moderate challenge

Calculate the volume and surface area of the frustum in the image below. A Creo part model was attached to the challenge for verification.

Square Frustum designed using Creo 7.0

Optional 1: Create a function that calculates the volume given the 3 dimensions above: edge length of the base, side edge length, and top face edge length.

Optional 2 (for Mathcad Prime 10 users): Use the slider advanced input control to change either the height of the slicing plane or length of the side edge, and recalculate the volume.

Hard challenge: The pyramid of least volume

“Of all the planes tangent to the ellipsoid
x2/a2 + y2/b2 + z2/c2 = 1
one of them cuts the pyramid of least possible volume from the first octant x ≥ 0, y ≥ 0, z ≥ 0. Show that the point of tangency of that plane is the centroid of the face ABC.”

The Mathematical Mechanic” by Mark Levi, section 3.5, figure 3.8

The pyramid in this situation has four sides. One of the corners is at the origin (0,0,0). The centroid is this case means the intersection of its medians. (Source: “The Mathematical Mechanic” by Mark Levi, section 3.5.)

The submissions

Five people submitted a total of six worksheets. The quality in all of them is quite amazing.

Frequent contributor Alan Stevens was the first person to submit a worksheet, and as usual, his worksheet can double as a teaching tool. The worksheet is laid out beautifully with text regions, images, and math regions with the comparison equals to operator to explain the logic. The final values for the volume and surface area are highlighted nicely. Since Alan performed the challenge using Mathcad Prime Express, he used an XY Plot to show volume as a function of the side edge length of the frustum.

User ppal submitted two worksheets, one for each challenge. His also makes excellent use of the documentation tools in Mathcad. The first worksheet uses two different methods to calculate the frustum volume. The first method involves integration and takes advantage of the slider advanced input control in Prime 10. The second method uses a triple integral in a pyramid coordinate system to calculate the volume. Neat stuff.

ppal’s second worksheet tackles the Pyramid of Least Volume. His solution method normalizes the ellipsoid to a sphere and incorporates Lagrange multipliers, derivatives, and symbolic evaluation to prove that the point of tangency is at the centroid of the triangle.

The next worksheet was from Werner, also a frequent contributor. He tackled the hard challenge with a very attractive worksheet. (Turning off the grid, formatting the text, and applying background colors to regions make a huge difference.) Werner walks through his proof using symbolic evaluation and partial derivatives to find the coordinate points of the plane that result in the minimum volume, calculates the center of gravity of its triangle, and sees if that is a point on the ellipsoid. Then he graphs the ellipsoid, triangle, and tangent plane with a little help from the CreateMesh function. Some really advanced work here.

Submission Montage for the Mathcad Community Challenge November 2024 frustums pyramids

Repeat contributor TTokoro submitted a worksheet that really pops off the page with its use of font color and highlight color. He calculates the angle and edge length for the original pyramid, which allows him to calculate the volume of the frustum by subtracting the volume of the smaller removed pyramid from the original pyramid. He makes use of a short program to facilitate calculation of the surface area. For the optional part, he used both slider and checkboxes to update a 3D Plot of the frustum. The worksheet concludes with a couple XY Plots of volume and surface area as a function of frustum height, including vertical and horizontal markers. It’s great to see a different approach compared to the other submissions.

The final worksheet was from Spauliszyn, a first-time contributor. I often comment on aesthetics, because that’s the first thing I typically notice. The lengthy worksheet had nice headers and footers, slider controls, 3D Plots, and collapsed areas that held many of the math regions. This is a fun worksheet to play with, because you can control manual or slider input, with sliders for the lengths of the top, bottom, and side edges, which update the 3D Plot of the frustum. The solution to the Pyramid of Least Volume also contains a slider control, which I did not expect. It starts with a couple 3D Plots depicting the ellipsoid and tangent plane. The formatting of the proof is simply beautiful, making use of derivatives and symbolic evaluation to prove that the centroid of the triangle coincides with the tangent point.

Takeaways

Once again, we see a variety of approaches that users take to solve the same problem, using a variety of tools within Mathcad. On the math side, we see functions, programs, symbolic evaluation, and matrices. Operators include derivatives, partial derivatives, and even the gradient operator. Advanced input controls include lists, check boxes, and sliders. There were quite a few XY and 3D Plots.

All of this was complemented by extensive use of documentation tools and images, making it so that someone unfamiliar with the problem being solved can understand the approaches and results. I highly recommend that you check out the submissions to see what you can use in your Mathcad worksheets.

Learn from the previous history of Mathcad Community Challenges here. You can also subscribe to when new challenges are up from there.

Up Next

Subscribe to the Mathcad Minute.

Learn about the new Mathcad challenges when they happen. Subscribe to our monthly newsletter. Subscribe Now
Dave Martin

Dave Martin is a Creo, Windchill, and PTC Mathcad instructor and consultant. He is the author of the books “Top Down Design in Creo Parametric,” “Design Intent in Creo Parametric,” and “Configuring Creo Parametric,” all available at amazon.com. He can be reached at [email protected].

Dave currently works as the configuration manager for Elroy Air, which develops autonomous aerial vehicles for middle-mile delivery. Previous employers include Blue Origin, Amazon Prime Air, Amazon Lab126, and PTC. He holds a degree in Mechanical Engineering from MIT and is a former armor officer in the United States Army Reserves.

Continue Reading