Programming Math Puzzlers

I teach a 40-minute enrichment class at the end of the day called “Computer-Based Math”, which is an intro to programming, but with an eye toward the math that makes interesting things happen on the computer. A couple of the topics we’ve explored as a class include:


I started with this topic, because when your computer program behaves a little unpredictably, it becomes so addictive and really hooks the students. We wrote programs to generate random numbers, such as coordinates for images, and then to create lists (beginning with arrays in JavaScript) and pull an element randomly from the list.

Jack created this color-matching game. I used it as an example in another math class to explore the difference between experimental and theoretical probability.  It looks like every color should show up as frequently as every other color, but as students played it and tallied results, the Green/Green combination was far more likely than any other. The reason why is interesting. Do you see it?

Jack's Color Match game shows green more than any other color. Interesting reason why.

Jack’s Color Match game shows green more than any other color. Interesting reason why.


Animation is another feature of games that can be addictive to play with, and the basics are pretty easy to understand. Take an object’s (x,y) coordinates and change them at a steady rate, and the object moves faster or slower.

Nathan literally just played and experimented with the rule for changing an object’s (x,y) coordinates and “discovered” an algorithm for making an object move in a circle. It’s really cool. I feel as though I understood why this algorithm creates a circular path at some point in my life, but I don’t remember why anymore. What’s the relationship between Nathan’s rule and the equation for a circle, r-squared = x-squared + y-squared?  Play with the initial values of x and y, and the denominators of the animation rule, and you see some pretty interesting stuff.

Nathan's accidental circle animation.

Nathan’s accidental circle animation.

Gabby made a clever “Frogger” game which explored the math behind collisions.  A circle is positioned according to its center, but a rectangle is positioned by its top-left corner.  Finessing the details of checking whether the outside edge of a circle collided with the outside edge of a rectangle took some thought!

Gabby's Frogger Game

Gabby’s Frogger Game

This class is not standards-based, is not graded, and so we can be more free to explore topics the students are interested in. That said, I look for connections to math standards to help the students with their learning. Goals with expressions, variables, and geometry are easy to include in programming projects. To give the students an audience, we plan mini-showcases a couple of times a semester where we invite other classes to come see our work, we give presentations about what we learned, and we have food (always an important part of real-world meetings). The students are starting to explore functions and the programming behind simulated gravity. When we have some more work to share, I will post it!


Tags: , , , ,

About dupriestmath

I'm a former software engineer who has taught middle school math and computer science for the past 6 years. I believe every kid has the right to be a thinker. I started this blog to save resources for integrating programming in the Common Core math classroom. I also use it to save my lessons and reflections from teaching budding computer scientists! Coding has transformed how I teach and think. You'll love what it does for you. You should try it.

One response to “Programming Math Puzzlers”

  1. mathtuition88 says :

    The games the kids programmed are really fun! I like the Frogger game very much.
    Regarding the Color Match game green-green combination, just a guess it’s due to rounding. (rounding a number from (0,2) has highest chance of being 1)

    Have a great day!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: