Lesson goal: Father and Son Age Puzzle

Previous: Sum of consecutive squares | Home | Next: Principle of Inclusion-Exclusion

In the 1971 MAA High School Mathematics Contest (Problem #25), students were challenged with this algebra puzzle: A teenage boy wrote his own age after his father's age. From this new 4-digit number he subtracted the difference of their ages to get 4,289. What was the sum of their ages? Let $F$ be the father's 2-digit age, and let $B$ be the boy's teenage age ($13 \le B \le 19$). When the boy writes his age after his father's, the resulting 4-digit number is: $$100 \times F + B$$ The difference between their ages is $F - B$. Subtracting the difference from the 4-digit number: $$(100F + B) - (F - B) = 4289$$ $$99F + 2B = 4289$$ This is a Diophantine equation (an equation where we seek integer solutions). Instead of working through division remainders by hand, we can write a pair of nested for-loops and an if-statement to test each possible age combination!
num = 100 * F + B
diff = F - B

if num - diff == 4289 then

  print("Found! Father:", F, "Boy:", B, "Sum:", F + B)
end
Move the mouse over a dotted box for more information.

Because the boy is a teenager, $B$ must be between 13 and 19. This narrow range makes the search instantaneous on a computer!

Now you try. Fill in num = 100 * F + B, diff = F - B, and the if test. Run the program to find the father's and son's ages, and their sum!

Type your code here:


See your results here: