[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]


I suppose that most everyone here in the States has heard of "Click and "Clack, the Tappet brothers" (a.k.a. Ray and Tom Magliozzi) . They have a weekly "Car Talk" radio show on National Public Radio which combines entertainment with occasionally useful automotive advice. One of the features each week is a "Puzzler", sometimes automotive, sometimes a word puzzle, and sometimes math or logic related. Like last week's When you add the age of a ship and the age of its boiler, it totals 42 years. So S + B = 42. The ship is twice as old as the boiler was when the ship was as old as the boiler is now. How old are they? That one could be solved with simple algebra and a few trials to find equations that fit the syntax. This week's seemed to deserve a programmed solution, even though it's quite a simple one (the program that is, not the puzzle): "Recently I had a visit with my mom and we
realized that the two digits that make up my age when
reversed resulted in her age. For example, if she's 73, I'm 37. We wondered how
often this has happened over
the years but we got sidetracked with other topics and we never came up with an
answer. The Delphi program which finds the solution required about 30 lines of code. It works like this: The common characteristic of the 8 pairs of SonMother ages we are looking for must all have the same age difference. So we'll try all the feasible age differences between Mother and Son, say from 10 to 50 years. It's probably safe to assume that the oldest feasible Mom's age is less than 100 so we only need to check son's ages up 100 minus the current difference being checked. Given those assumptions, the Delphi code below probably describes the algorithm better than text, even for nonprogrammers. {Comments in Delphi are enclosed in curly brackets} for diff:=10 to 50 do
{loop on possible age differences} Running/Exploring the Program

[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 20002018, Gary Darby All rights reserved. 