# 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:

PROBABILITY

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?

ANIMATION AND COLLISIONS

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.

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!

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!

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!