teaching machines

Another Integer Triangle Wave

I’ve across another way to generate a triangular wave. So exciting! Recall from last time that I want to generate a pattern that looks like this: In this example, the period is 10. As before, we can generate a sawtooth wave with some help from modulus: $$y = \textrm{mod}(x, \textrm{period})$$ We can also generate a […]

Integer Triangle Wave

I encounter many of the same problems over and over again. But sometimes enough time elapses between one encounter with a problem and the next that I’ve forgotten how to solve it. I start to doubt my qualifications as a teacher. “That guy can’t even learn. How could we trust him to teach?” I think […]

Fitting a Rectangle Inside a Rectangle

A common problem in computer graphics and user interfaces is scaling one rectangle to fit inside another—preserving the rectangle’s aspect ratio. For example, I’ve encountered this problem in the following situations: Placing an image of arbitrary size on a button of fixed size. Overlay a map on a corner of a game scene. Squeezing an image […]

Generating Digital Audio for a Pitch

Sound is a wave of pressure that travels through the environment. My high school physics teacher Mr. Oppelt told me that pressure is force applied to a surface, and so when we say that music has a beat, we’re quite right. It “beats” on things. Like our ear drums. It beats on other things too, […]

Generating utterance WAVs

I’m going to ask my students to write some C code to create an audio pronunciation of a number. For instance, 137 is pronounced “one hundred thirty-seven.” As input, I will give them WAV files containing the separated pronunciations of all the number words that are needed. They’ll need to read these files in, concatenate […]

Drawing a line

I have a friend who is trying to get a bunch of first semester programmers to plot a line between two points into a 2-D pixel array. Bresenham’s is out of the question. A first attempt was a slope-based approach. I never saw the code he came up with, but it wasn’t able to handle […]

Is a point in a polygon?

Here’s a practice attempt at recording a mini-lecture. I’m convinced now of its difficulty. Enjoy the abrupt audio changes, the bad handwriting, and me drowning in self-consciousness. I did not use Camtasia Studio to assemble this. In this video, we develop an algorithm for checking whether or not a point falls within a polygon. The […]

How to make a 3-D present for your wife

In summer-fall 2009, I read Douglas Hofstadter’s Godel, Escher, and Bach. It took me that long. It was full of cleverness, but I think most of the message was lost on me. That’s okay, because I was inspired by the cover image to make my wife a keychain of her initials. Hofstadter carved what he […]

Lucy and the Linear Search

My wife and I are reading C.S. Lewis’ The Voyage of the Dawn Treader together before we go see it in the theater. We stumbled upon this nice little discussion on computational complexity in chapter 10: One thing that worried [Lucy] a good deal was the size of the Book. The Chief Voice had not been able […]