January 5th, 2011 at 10:57 pm by Dr. Drang
I had a long drive today, and I passed the time by thinking about making a new set of math practice sheets for my ten-year-old son. This year has been fraction-heavy, so I thought I’d start with a simple one: a page with a bunch of proper fractions that may or may not need to be reduced to lowest terms.
It’s like all my other math worksheets, an HTML page that generates a new set of problems every time you open or refresh the page. The numbers are big, easy to read, and have enough space around them for the intermediate work. I don’t give the answers—that’s for you and your child to figure out, together or separately.
Here’s the code itself:
The basic idea is simple. For each problem, the `singleProblem function (Lines 81-91) selects a proper fraction in lowest terms, multiplies it by a random integer, and generates the HTML for displaying it on the sheet.
singleProblem get the list of fractions to pick from? That’s the job of the
fractions function, which is defined on Lines 66-75 and called on Line 78. It generates an array of all possible proper fractions in lowest terms for a given list of denominators. For example, if we gave it the list
[2, 3, 4, 5, 6], it would return the list of lists
[1, 2] [1, 3], [2, 3] [1, 4], [3, 4] [1, 5], [2, 5], [3, 5], [4, 5] [1, 6], [5, 6]
where each sublist is a [numerator, denominator] pair. Note that pairs like
[2, 4] and
[4, 6] are not returned, as these are not in lowest terms. These pairs are filtered out of the results by making sure that the numerator and denominator are relatively prime. The filtering is done through the
gcd function in Lines 39-50. If the greatest common divisor of two numbers is one, they’re relatively prime. The
gcd function uses Euclid’s Algorithm and is a slight adaptation of this one by Robert Campbell of the University of Maryland, Baltimore County.
I chose to generate fractions with denominators of 2 through 12, excluding 11. I wanted the answers to be fairly simple but not restricted to single-digit denominators. Twelve seemed like a good upper limit. I decided to exclude 11 from the list of possible denominators because if I hadn’t it would have dominated the answers. Recall that 11 is prime, so there are 10 proper fractions in lowest terms with 11 as the denominator—far more than any of the other denominators I was using. Because
singleProblem makes a uniform random choice from among the list of possible fractions, leaving 11 in the list would have meant that it would be the denominator in nearly one-fourth of the answers, which just didn’t seem right.
The multiplier—the number that “unreduces” the fractions—is chosen at random for each problem and can be any integer in the range 1-12, inclusive. Note that this means that some fractions on the sheet will multiplied by 1 and will therefore already be in lowest terms. These are meant to keep your student on his or her toes.
I’ve tested the page in Firefox, Google Chrome, and Safari, and it works for me. Let me know if you have any problems with it. Screenshots and error messages are appreciated when debugging.