The product of the ages of Timothy’s children is the square of the sum of their ages. Timothy has at least 2 children but less than 8 children. All of his children are at least 2 years old and at most 14 years old. All the ages of the children are different and the age of each child is a positive integer when expressed in years.
How many children are there and what are their ages?
DECLARE SUB choose (child!)
DIM SHARED n, childage(8)
CLS
FOR n = 2 TO 7
choose 1
NEXT
SUB choose (child)
st = 2
IF child > 1 THEN
st = childage(child - 1) + 1
END IF
FOR age = st TO 14
childage(child) = age
IF child < n THEN
choose child + 1
ELSE
prod = 1: sum = 0
FOR i = 1 TO n
prod = prod * childage(i)
sum = sum + childage(i)
NEXT i
IF prod = sum * sum THEN
FOR i = 1 TO n
PRINT childage(i);
NEXT i
PRINT , prod; sum: PRINT
END IF
END IF
NEXT age
END SUB
produces
2 4 6 12 576 24
indicating four children, ages 2, 4, 6 and 12, adding to 24 and multiplying out to 576.
|
Posted by Charlie
on 2008-11-22 19:57:52 |