Algorithm for finding "fact families"

279 Views Asked by At

My friend's 3rd grader encountered the following question regarding "fact families" on her math homework:

fact families

I was in 3rd grade sometime in the 1980s, so I don't believe I ever encountered this term before. Her mother was having some trouble interpreting the question, so after a little research I wrote a short Python script to generate these "fact families":

vars = [(i,j) for i in xrange(2,100) for j in xrange (2,100) if j >= i and i*j < 100]

output = []

for i,j in vars:
    product = i*j
    digits = [i,j,product]
    seen = []

    for digit in str(i) + str(j) + str(product):
        if digit not in seen:
            seen.append(digit)

    if len(seen) == 3:
       output.append(digits)

print output
print len(output)

With the result:

[[2, 3, 6], [2, 4, 8], [2, 6, 12], [2, 10, 20], [2, 12, 24], [2, 20, 40], [2, 21, 42], [2, 24, 48], [2, 25, 50], [2, 26, 52], [2, 33, 66], [2, 42, 84], [2, 44, 88], [3, 5, 15], [3, 10, 30], [3, 13, 39], [3, 22, 66], [3, 30, 90], [3, 31, 93], [4, 4, 16], [4, 6, 24], [4, 10, 40], [4, 16, 64], [4, 22, 88], [5, 7, 35], [5, 9, 45], [5, 10, 50], [5, 15, 75], [5, 19, 95], [6, 8, 48], [6, 10, 60], [6, 16, 96], [7, 7, 49], [7, 10, 70], [8, 8, 64], [8, 10, 80], [9, 9, 81], [9, 10, 90]]

38

I think the purpose of this exercise is to allow the student to practice their times tables or...something. I don't know that I agree with this type of mathematics education, but as soliciting responses on such an issue would be primarily opinion-based I guess I will refrain from asking about that directly.

The algorithm in the code searches for the families with three different digits probably the same way a 3rd grader would: scanning the numbers in all combinations of factors and products and noting the sets where only three have appeared, i.e. brute force. Is there any more clever (computationally efficient) way to generate these sets?