Eman said:
In the first problem with the ages, I found the ages are 3, 5, and 15. (I used a program to figure this out.)
How would I go about figuring this out with the information given?
From post #10 use the following :
#1. sum = 23
#2. sum of squares = 259
#3. sum of pairwise products = 135, an odd number.
First sum = odd means you must have (a)1 odd + 2 evens OR (b)3 odds. Now, case(a) can be eliminated by using fact #3, since in that case, all the pairwise products (oe, oe, ee) will be even.
So, we are looking for 3 odd numbers.
Next use the fact that the for a given sum (or perimeter of cuboid) the sum of squares (or length of body diagonal) is minimized when the numbers are equal (when the object is a cube).
So, in this case given that sum =23, if the numbers were roughly equal, the sum of squares would be less than 200 (64+64+49 = 177), but this is actually much larger (259). So we must consider extremely unequal numbers. So one of the following cases must be true : (i) 1 number much less than 8 and 2 numbers greater than 8, OR (ii) 1 number much greater than 8 and 2 numbers less than 8. Now we can eliminate most of case (i) through the following reasoning :
sum of squares of the 2 larger numbers < 259...so the only allowed pairs are (9,9), (9,11), (9,13), (9,15), (11,11). All other pairs are eliminated. It's simple to go through these 5 cases and see that none of them work.
Now you are left with case (ii). Clearly, the maximum value of the largest number is 15 since17^2 = 289 > 259. And since we want an extreme case, we start with (15,y,z) followed by (13,y,z) and (11,y,z) - this last case being pretty unlikely. For the first case, y+z = 23-15 = 8. So possibilities are (1,7) and (3,5). Clearly, the first pair fails but the second works.
So, were are through...the solution is (15,5,3).
In your code, you would have x = 1..21, y = 1..22-x , z = 23 - x - y - a total of 210 computations. Notice that we had to make only 6 computations (of wrong sets) before finding the correct set.