Everyone loves puzzles, right? This math puzzle from the YouTuber Numberphile poses a simple question: How can a mouse escape from a cat. But wait! It's not just a mouse running on the ground. Instead, the mouse is swimming in a circular pool, and the cat is on the outside of the pool. The cat can move 4 times faster on the ground than the mouse can swim. So, how does the mouse escape?

Although it might be possible to find a solution to this puzzle with just a paper and pencil, it's much more fun to build a numerical model. With a numerical model, a problem is solved by using small steps. In this case, it will be small steps of time (let's say 0.01 seconds). During this short time interval, we can make some approximations about the motion of both the cat and the mouse that will be very simple to solve. Of course you can't see if the mouse escapes in just 0.01 seconds. That means you will need to repeat these simple calculations many times. If you want to run the model for just 1 second, that would cover 100 steps in this case.

For many problems, like a ball falling with air resistance, we can use real physics concepts in each of these tiny steps. For this cat and mouse, we are going to have to make up some "rules." Let's start with the following behaviors for both animals.

The cat will move along the circle with a constant speed and travel to the point that is closest to the mouse.

The mouse will travel with a constant speed and always move in a direction away from the cat.

Those are the rules, but we still need to break this into pieces. I'm going to build the model in Python—well, actually it's VPython. This is Python with a visual module that allows me to easily visualize what's happening with a 3D animation.

I will go ahead and share this program below. You can run it (press the Play button) and look at the code (with the pencil icon). After that, I will go over some of the important details.

Let me start with the cat details. There is one tricky thing to figure out—should the cat move clockwise or counter­clockwise? There might be a better way to determine the cat's direction, but I used the cross product. The cross product is a vector operation that returns another vector. This resultant vector is perpendicular to both of the starting vectors. If I take the cross product of the vector position of the cat and the position of the mouse, I will get a result in the z-direction (the pool is in the x-y plane). If the mouse is to the left of the cat, this cross product will be in the positive z-direction. Otherwise, it will be in the negative z-direction. I can use this to set the sign on the cat's angular velocity to move it.