The puzzle: David and Anton puzzle
David and Anton’s ages combined equals 65.
David is currently three times as old as Anton was when David was half as old as Anton will be when Anton is three times as old as David was when David was three times as old as Anton. How old is David?
Lets represent the ages of David and Anton with these two functions:
d(t) = t - td
a(t) = t - ta
Where td
and ta
are the birth dates of respectively David and Anton.
Now derive several equations from the story:
Equation | Sentence |
---|---|
d(now) + a(now) = 65 | “David and Anton’s ages combined equals 65.” |
d(now) = 3 * a(tdhalf) | “David is currently three times as old as Anton was when David was half” |
d(tdhalf) = 0.5 * a(tathree) | “when David was half as old as Anton will be when Anton is three” |
a(tathree) = 3 * d(tdthree) | “when Anton is three times as old as David was when David was three” |
d(tdthree) = 3 * a(tdthree) | “when David was three times as old as Anton.” |
{tdthree, tdhalf} < now < tathree | Using the verb tense of the various sentences. |
Substituting the age formulas we get:
(now-td) + (now-ta) = 65
(now-td) = 3 * (tdhalf-ta)
(tdhalf-td) = 0.5 * (tathree-ta)
(tathree-ta) = 3 * (tdthree-td)
(tdthree-td) = 3 * (tdthree-ta)
Now substituting the differences A-B with: (now-B)-(now-A)
(now-td) + (now-ta) = 65
(now-td) = 3 * ((now-ta)-(now-tdhalf))
((now-td)-(now-tdhalf)) = 0.5 * ((now-ta)-(now-tathree))
((now-ta)-(now-tathree)) = 3 * ((now-td)-(now-tdthree))
((now-td)-(now-tdthree)) = 3 * ((now-ta)-(now-tdthree))
And now substituting now-'t'var
with 'A'var
in all equations, where A
means ‘age’:
Ad + Aa = 65
Ad = 3 * (Aa-Adhalf)
(Ad-Adhalf) = 0.5 * (Aa-Aathree)
(Aa-Aathree) = 3 * (Ad-Adthree)
(Ad-Adthree) = 3 * (Aa-Adthree)
These are 5 equations in 5 variables, which we can solve, rewriting Ahis as a matrix equation:
+1 * Ad +1 * Aa = 65
+1 * Ad -3 * Aa +3 * Adhalf = 0
+1 * Ad -0.5 * Aa -1 * Adhalf +0.5 * Aathree = 0
-3 * Ad +1 * Aa -1 * Aathree +3 * Adthree = 0
+1 * Ad -3 * Aa +2 * Adthree = 0
We get this matrix equation:
[ +1 +1 0 0 0 ] [ Ad ] [ 65 ]
[ +1 -3 +3 0 0 ] [ Aa ] [ 0 ]
[ +1 -0.5 -1 +0.5 0 ] * [ Adhalf ] = [ 0 ]
[ -3 +1 0 -1 +3 ] [ Aathree ] [ 0 ]
[ +1 -3 0 0 +2 ] [ Adthree ] [ 0 ]
We can solve this with the help of numpy:
import numpy as np
a = np.array([
[ +1, +1, 0, 0, 0 ],
[ +1, -3, +3, 0, 0 ],
[ +1, -0.5, -1, +0.5, 0 ],
[ -3, +1, 0, -1, +3 ],
[ +1, -3, 0, 0, +2 ],
])
b = np.array([65, 0, 0, 0, 0])
x = np.linalg.solve(a, b)
print(x)
Which will output:
[ 37.5 27.5 15. -17.5 22.5]
So the solution is:
Ad = 37.5
Aa = 27.5
Adhalf = 15.0
Aathree = -17.5
Adthree = 22.5
So David is now 37.5 years old.